cmd/compile: fold redundant zero-extension after signed load on arm64#10
Open
hbrooks wants to merge 1 commit into
Open
cmd/compile: fold redundant zero-extension after signed load on arm64#10hbrooks wants to merge 1 commit into
hbrooks 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, #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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Originally PR golang#79652 in golang/go by @gaul