Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: unnecessary register moves #59288

Closed
rip-create-your-account opened this issue Mar 28, 2023 · 2 comments
Closed

cmd/compile: unnecessary register moves #59288

rip-create-your-account opened this issue Mar 28, 2023 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge Performance
Milestone

Comments

@rip-create-your-account

What version of Go are you using (go version)?

$ go version
go version devel go1.21-3ed8a1e629 Tue Mar 28 05:41:44 2023 +0000 linux/amd64

Does this issue reproduce with the latest release?

Not on go1.20.2. The generated assembly is in other ways very different to gotip.

What did you do?

https://go.dev/play/p/eKdUtP-irZa

The generated assembly for the Checksum function contains instructions that to my understanding are unnecessary. By removing the []byte return value (like in the Checksum2 function) the generated code for the loop body is what I expected.

What did you expect to see?

The generated assembly for the Checksum function:

...
MOVQ 0x30(AX), DI
BSWAP DI
...

What did you see instead?

There is one occurrence of:

...
MOVQ 0x28(AX), R13
BSWAP R13
vvv
MOVQ 0x30(AX), R15
BSWAP R15
MOVQ R15, DI
^^^
MOVQ 0x38(AX), R15
BSWAP R15
...

My understanding is that the MOVQ first to R15 just to then move it to DI is unnecessary. MOVQ directly to DI is what I expected.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 28, 2023
@randall77
Copy link
Contributor

The register allocator is trying and failing to keep DI unoccupied because it thinks it needs it for the return value (the uint16 one).
I think the priorities are just wrong. Saving the register may help later. Moving the value definitely costs now.

@randall77 randall77 added this to the Go1.21 milestone Mar 28, 2023
@randall77 randall77 self-assigned this Mar 28, 2023
@gopherbot
Copy link

Change https://go.dev/cl/479895 mentions this issue: cmd/compile: lower priority of avoiding registers

johanbrandhorst pushed a commit to Pryz/go that referenced this issue Mar 28, 2023
We avoid allocating registers when we know they may have a fixed use
later (arg/return value, or the CX shift argument to SHRQ, etc.) But
it isn't worth avoiding that register if it requires moving another
register.

A move we may have to do later is not worth a move we definitely have
to do now.

Fixes golang#59288

Change-Id: Ibbdcbaea9caee0c5f3e0d6956a1a084ba89757a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/479895
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
@golang golang locked and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge Performance
Projects
None yet
Development

No branches or pull requests

3 participants