Skip to content

cmd/compile/internal/ssa: elide redundant 32-bit zero extensions on arm64 - #80566

Closed
andig wants to merge 1 commit into
golang:masterfrom
andig:arm64-zeroupper32
Closed

cmd/compile/internal/ssa: elide redundant 32-bit zero extensions on arm64#80566
andig wants to merge 1 commit into
golang:masterfrom
andig:arm64-zeroupper32

Conversation

@andig

@andig andig commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

ZeroUpper32Bits knows about arm64's W-form ALU results, but not about its
zero-extending loads and register moves. The late lower rule
(MOVWUreg x) && ZeroUpper32Bits(x, 3) => x therefore never fires for a
value that came from MOVWUload/MOVHUload/MOVBUload or from a narrower
MOV*Ureg.

With a single use the extension still folds away, via
(MOVWUreg x:(MOVWUload _ _)) => (MOVDreg x) and
(MOVDreg x) && x.Uses == 1 => (MOVDnop x). With a second consumer -- a
loaded uint32 field used both as a slice index and in a bounds compare,
the regexp onepass shape -- the MOVDreg survives as a real MOVD Rx,Ry
register copy.

Add the arm64 zero-extending loads and register moves to
ZeroUpper32Bits, mirroring the byte and halfword op lists that CL 804064
adds to ZeroUpper56Bits and ZeroUpper48Bits. The two changes are
independent; this one applies on its own.

Measured at 7b4aab8 with go build -a -gcflags=-S std at
GOARCH=arm64: 117 fewer register copies (runtime -36, regexp -26,
internal/zstd -11, internal/coverage/cformat -8) for -592 bytes of
function text across 26 packages, with a single-copy regression in
errors.

Updates #43357

@google-cla

google-cla Bot commented Jul 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@andig

This comment was marked as resolved.

@andig
andig force-pushed the arm64-zeroupper32 branch from ed504a9 to cff9a65 Compare July 25, 2026 09:43
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: cff9a65) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/805860.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@andig
andig force-pushed the arm64-zeroupper32 branch from cff9a65 to f5fce77 Compare July 25, 2026 09:50
…rm64

ZeroUpper32Bits knows about arm64's W-form ALU results, but not about
its zero-extending loads and register moves. The late lower rule
(MOVWUreg x) && ZeroUpper32Bits(x, 3) => x therefore never fires for a
value that came from MOVWUload/MOVHUload/MOVBUload or from a narrower
MOV*Ureg.

When such a value has a single use the extension still folds away, via
(MOVWUreg x:(MOVWUload _ _)) => (MOVDreg x) and (MOVDreg x) && x.Uses == 1
=> (MOVDnop x). With a second consumer -- a loaded uint32 field used both
as a slice index and in a bounds compare, the regexp onepass shape -- the
MOVDreg survives as a real MOVD Rx,Ry register copy.

Add the arm64 zero-extending loads and register moves to ZeroUpper32Bits,
mirroring the byte and halfword op lists that CL 804064 adds to
ZeroUpper56Bits and ZeroUpper48Bits.

This removes 117 register copies in std at GOARCH=arm64 (runtime -36,
regexp -26, internal/zstd -11, internal/coverage/cformat -8) for -592
bytes of function text, with a single-copy regression in errors.

Updates golang#43357
@andig
andig force-pushed the arm64-zeroupper32 branch from f5fce77 to afe5236 Compare July 25, 2026 09:56
@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: afe5236) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/805860.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Andreas Goetz:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Jorropo:

Patch Set 2: Auto-Submit+1 Code-Review+2 Commit-Queue+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 2:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-07-26T03:02:19Z","revision":"47e9cdce905d93f8c6a6a8a499c9a9587d9dd334"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Jorropo:

Patch Set 2: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_55763>)


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 2:

This CL has failed the run. Reason:

Tryjob golang/try/gotip-windows-386 has failed with summary (view all results):


To reproduce, try gomote repro 8675248901453639969.

Additional links for debugging:


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 2: LUCI-TryBot-Result-1


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Andreas Goetz:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Keith Randall:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/805860.
After addressing review feedback, remember to publish your drafts!

@andig andig closed this Jul 28, 2026
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