diff options
| author | Joel Sing <joel@sing.id.au> | 2025-12-03 00:42:12 +1100 |
|---|---|---|
| committer | Joel Sing <joel@sing.id.au> | 2026-03-10 05:04:41 -0700 |
| commit | 0a0c9c88fdee8317c1f9e10c5e61d3cf7428c7c1 (patch) | |
| tree | f80aba98cbd729aa56563cb76fd768c8c728f7c2 /src/cmd | |
| parent | def4e491be636d5fda1f1d36bd17fbf3f8a37ea7 (diff) | |
| download | go-0a0c9c88fdee8317c1f9e10c5e61d3cf7428c7c1.tar.xz | |
cmd/internal/obj/riscv: factor out constant materialisation identification
Change-Id: Ia7fedd934ecc2b11cb0de445f299dc5c6004e7b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/748960
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Mark Ryan <markdryan@meta.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/internal/obj/riscv/obj.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index e9005fe0db..ac2b54187d 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -139,11 +139,11 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { p.As = AEBREAK case AMOV: - if p.From.Type == obj.TYPE_CONST && p.From.Name == obj.NAME_NONE && p.From.Reg == obj.REG_NONE && int64(int32(p.From.Offset)) != p.From.Offset { - if isShiftConst(p.From.Offset) { + if p.From.Type == obj.TYPE_CONST && p.From.Name == obj.NAME_NONE && p.From.Reg == obj.REG_NONE { + if isMaterialisableConst(p.From.Offset) { break } - // Put >32-bit constants in memory and load them. + // Put non-materialisable constants in memory and load them. p.From.Type = obj.TYPE_MEM p.From.Sym = ctxt.Int64Sym(p.From.Offset) p.From.Name = obj.NAME_EXTERN @@ -3479,6 +3479,17 @@ func isShiftConst(v int64) bool { return ok && (lsh > 0 || rsh > 0) } +// isMaterialisableConst indicates whether a constant can be materialised +// via a small sequence of instructions. +func isMaterialisableConst(v int64) bool { + // Signed 32 bit value that can be constructed with one or two instructions + // (ADDIW or LUI+ADDIW). + if int64(int32(v)) == v { + return true + } + return isShiftConst(v) +} + type instruction struct { p *obj.Prog // Prog that instruction is for as obj.As // Assembler opcode |
