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: incorrect arm/arm64 simplification rules #48473

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

cmd/compile: incorrect arm/arm64 simplification rules #48473

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

Comments

@randall77
Copy link
Contributor

Both arm and arm64 have rules like:

(SUBshiftLL x (SLLconst x [c]) [d]) && c==d => (MOVDconst [0])

This actually encodes the identity x - x<<c<<c == 0, which is incorrect. It should be

(SUBshiftLL (SLLconst x [c]) x [d]) && c==d => (MOVDconst [0])

Which encodes the correct identity x<<c - x<<c == 0.

It turns out to be quite hard to trigger this bad rule, as x<<c<<c is almost always reduced by the generic rewrite pass. But here's a case which gets through:

package main

func f(x uint64) uint64 {
	s := "\x05"
	c := s[0]
	return x - x<<c<<5
}

func main() {
	println(f(5))
}

This should print some giant number (18446744073709546501), but on arm64 it prints 0.

@cherryyz

@randall77
Copy link
Contributor Author

@gopherbot please open backport issues.

@gopherbot
Copy link

Backport issue(s) opened: #48474 (for 1.16), #48475 (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/350913 mentions this issue: cmd/compile: fix simplification rules on arm/arm64

@ALTree ALTree added this to the Go1.18 milestone Sep 20, 2021
@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 Sep 20, 2022
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.
Projects
None yet
Development

No branches or pull requests

3 participants