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
Assignees
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Sep 20, 2021

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

@randall77 randall77 commented Sep 20, 2021

@gopherbot please open backport issues

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 20, 2021

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.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 20, 2021

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants