-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: Instruction split on amd64 #56476
Comments
cc @golang/compiler , though questions might be better suited for golang-dev. |
Only see two BSFQ instructions with go version devel go1.20-b726b0cadb Fri Oct 28 23:35:08 2022 +0000 linux/amd64 One is in B() and the other is from B() being in-lined into main(). |
I find go tip in compiler explorer is not go tip. I add -goversion in compiler options, only to see: And I can't reproduce with current go tip(go version devel go1.20-3c17053bba Sat Oct 29 00:40:18 2022 +0000 linux/amd64) |
@wdvxdr1123 I can reproduce locally on 1.19.2 - you must check the main() function where it is inlined:
Output above is produced with:
|
@klauspost Yes, I can reproduce with go 1.19.2. I think this issue has been fixed in 669ec54. I revert this commit in my local branch and got the bad assembly output. |
If it is gone in tip we can just close it. Thanks for taking the time to investigate. |
What version of Go are you using (
go version
)?Latest version.
I just want to confirm that this is intended behavior.
Does this issue reproduce with the latest release?
Yes.
What did you do?
I was investigating assembly output from various variations and noticed some peculiar output with go tip amd64 compiler:
Code in question:
bits.TrailingZeros64(a^b) >= 51
Godbolt output: https://godbolt.org/z/z1jfE85ax
Playground link of the same code: https://go.dev/play/p/UpuJvUnS1Lm
What did you expect to see?
What did you see instead?
My main objection is that is re-executes BSF.
It seems to calculate the result on CX, and then later it re-computes to get the flag for the CMOV. If code is simplified (by removing call to A or observing the not-inlined function), this split goes away.
On Intel this is a rather expensive way to check if AX is zero. If this is a more common pattern it seems like it should be avoided. I know I cannot expect perfect assembly, but this seems a bit odd to me.
The text was updated successfully, but these errors were encountered: