-
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: incorrect left shift result on s390x #72018
Comments
Related Issues
Related Discussions (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
I think the bug is here: go/src/cmd/compile/internal/ssa/_gen/S390X.rules Lines 272 to 276 in d31c805
We're comparing against 64 all the time, instead of the width of the shift. |
Same result on go1.24.0. |
CC @golang/s390x |
@RaduBerinde thanks for reporting the issue. I tried reproducing the same on linux/s390x with go1.23.6 & go1.24.0 versions but I could not able to reproduce it.
@RaduBerinde Could you please share exact test you ran? |
I think capacity needs to not constant fold. Pass the |
Yes, it's probably because of constant folding. It was part of a bigger project, it would be unwieldy to reproduce the exact code. Just try this: package main
import "fmt"
func shift(n int) uint32 {
return uint32(1) << n
}
func main() {
for i := 0; i < 40; i++ {
fmt.Printf("%d: %d\n", i, shift(i))
}
}
|
BTW something like the above should be a basic test for shifts on all platforms. |
Yes, I am surprised we don't already have a test for this. |
I noticed this was added to Backlog. I'd like to make a kind appeal to consider prioritizing this as it can lead to failures that are hard to debug. From Keith's comment, it sounds like a simple fix. |
I'll let the s390x folks prioritize this. |
@RaduBerinde multiarch/qemu-user-static is unfortunately very old and a lot has been fixed. This is qemu issue, fix for this issue is target/s390x: Fix shifting 32-bit values for more than 31 bits which already fixed in |
@srinivas-pokala thank you so much for finding that! I will try to figure out how to use a more recent version. I will close the issue once I confirm. |
Change https://go.dev/cl/654316 mentions this issue: |
I confirmed that it works fine with a more recent qemu:
|
Update #72018 Change-Id: I3188019658c37da3c31f06472023b39e13170ebf Reviewed-on: https://go-review.googlesource.com/c/go/+/654316 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Keith Randall <khr@google.com>
Go version
go1.23.6 linux/s390x
Output of
go env
in your module/workspace:What did you do?
Ran this code in a test:
I ran it on an amd64 linux machine using qemu (it is possible but unlikely that it is a qemu issue):
What did you see happen?
Prints out:
What did you expect to see?
So
(1 << 32)
comes out to1
. I expected to see 0. The spec is clear about this: "Shifts behave as if the left operand is shifted n times by 1 for a shift count of n."The text was updated successfully, but these errors were encountered: