Skip to content

cmd/compile: fold redundant zero-extension after signed load on arm64#10

Open
hbrooks wants to merge 1 commit into
masterfrom
demo/pr-79652
Open

cmd/compile: fold redundant zero-extension after signed load on arm64#10
hbrooks wants to merge 1 commit into
masterfrom
demo/pr-79652

Conversation

@hbrooks
Copy link
Copy Markdown

@hbrooks hbrooks commented May 28, 2026

Originally PR golang#79652 in golang/go by @gaul

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, #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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants