cmd/compile: fold redundant zero-extension after signed load on arm64#79652
cmd/compile: fold redundant zero-extension after signed load on arm64#79652gaul wants to merge 1 commit into
Conversation
When a sign-extending load (LDRSB/LDRSH/LDRSW) is followed by a single
zero-extension, the upper bits produced by the load are immediately
overwritten and the extension is dead. The load can be switched to its
unsigned form (LDRB/LDRH/LDR) and the extension elided.
For example, code like
func F(s []int8, i int) bool { return s[i] == 0x5d }
previously generated
ldrsb x4, [x1, x3]
ubfx x4, x4, #0, golang#8
cmp w4, #0x5d
and now generates
ldrb w4, [x1, x3]
cmp w4, #0x5d
RISCV64 (RISCV64.rules) and MIPS (MIPS.rules) already had the equivalent
rewrite; ARM64 was missing it, including the indexed (loadidx) variants.
Found via armlint: LDRSx + zero-extension findings drop from 40 -> 1 on
gofmt and 547 -> 8 on cmd/go. Text section shrinks by 144 bytes
(0.0121%) on gofmt and 2416 bytes (0.0363%) on cmd/go.
|
This PR (HEAD: f36ef22) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/782960. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
|
Message from Keith Randall: Patch Set 1: Auto-Submit+1 Code-Review+2 Commit-Queue+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: Dry run: CV is trying the patch. Bot data: {"action":"start","triggered_at":"2026-05-26T15:25:58Z","revision":"90430747559572d0dcf26405458e5d9995c2c0f2"} Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
|
Message from Keith Randall: Patch Set 1: Code-Review+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
|
Message from Keith Randall: Patch Set 1: -Commit-Queue (Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_5200>) Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: This CL has passed the run Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
|
Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com: Patch Set 1: LUCI-TryBot-Result+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/782960. |
When a sign-extending load (LDRSB/LDRSH/LDRSW) is followed by a single
zero-extension, the upper bits produced by the load are immediately
overwritten and the extension is dead. The load can be switched to its
unsigned form (LDRB/LDRH/LDR) and the extension elided.
For example, code like
previously generated
and now generates
RISCV64 (RISCV64.rules) and MIPS (MIPS.rules) already had the equivalent
rewrite; ARM64 was missing it, including the indexed (loadidx) variants.
Found via armlint: LDRSx + zero-extension findings drop from 40 -> 1 on
gofmt and 547 -> 8 on cmd/go. Text section shrinks by 144 bytes
(0.0121%) on gofmt and 2416 bytes (0.0363%) on cmd/go.