-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: bad code generation for ARM (bounds test fails) #41780
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
Comments
I wonder if the (CMP x -y) => (CMN x y) is valid when the condition codes are used for unsigned comparison. |
Confirmed, the CMP to CMN transformation is not carry-bit-preserving. The failing rewrite:
evaluated:
In context, the full chain of rewrites for both comparisons (that are the same comparison):
|
This sounds an awful lot like https://go-review.googlesource.com/c/go/+/233097 |
Actually, that's the arm64 CL. The arm one was https://go-review.googlesource.com/c/go/+/236637/ |
Change https://golang.org/cl/259450 mentions this issue: |
@randall77 It's similar. I suppose I should figure out if the |
What version of Go are you using (
go version
)?and also
and also
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
Outputand also
go env
OutputWhat did you do?
Compile this program https://play.golang.org/p/TfpedZeakHY for GOARCH=arm GOOS=linux
Code also appears below:
What did you expect to see?
The playground output:
foo(&d)= 1
What did you see instead?
On an ARM:
The bug is very delicate, it depends on something going wrong in arm lowering/optimization to machine code, and it is in that dyslexia-inducing bit where comparisons are reversed, inverted, etc. The signature of the bug (seen in
ssa.html
) is that the comparison-d.dp >= len(powtab)
gets compiled into aCMN
instruction both at the comparison and at the bounds check; if this happens, something goes wrong. The pattern firing depends on the SSA variable numbering of the inputs to the originally generated CMP.From here, a complete dump of the debugging work, just collecting, not analyzing, that can happen later.
Ultimately, the code looks like this:

According to gdb, this is the code that is generated:
and this is the trace where it goes wrong:
The text was updated successfully, but these errors were encountered: