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: 64 bits shifts on arm get wrong results #48476

Closed
randall77 opened this issue Sep 20, 2021 · 3 comments
Closed

cmd/compile: 64 bits shifts on arm get wrong results #48476

randall77 opened this issue Sep 20, 2021 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@randall77
Copy link
Contributor

package main

//go:noinline
func f(x, y uint64) uint64 {
	s := "\x04"
	c := s[0]
	return x<<c<<4
}
func main() {
	println(f(1, 1))
}

Should print 256 (0x100), instead prints 1099511628032 (0x10000000100) on arm.

The problem is we build a SLLconst with a shift amount > 32. That in itself is ok, but we then copy the shift amount into a ORshiftLL, where the top bits are magically discarded.

The SLL with a large constant shift amount comes from the 64->32 bit lowering of shifts. We compute things like s-32 and 32-s (unsigned) for shift amounts in [0,63).

@randall77 randall77 added this to the Go1.18 milestone Sep 20, 2021
@randall77 randall77 self-assigned this Sep 20, 2021
@randall77
Copy link
Contributor Author

@gopherbot please open backport issues

@gopherbot
Copy link

Backport issue(s) opened: #48478 (for 1.16), #48479 (for 1.17).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot
Copy link

Change https://golang.org/cl/350969 mentions this issue: cmd/compile: ensure constant shift amounts are in range for arm

@ALTree ALTree added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 20, 2021
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants