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
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Sep 19, 2021

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

@randall77 randall77 commented Sep 19, 2021

@gopherbot please open backport issues.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 19, 2021

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.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 19, 2021

Change https://golang.org/cl/350913 mentions this issue: cmd/compile: fix simplification rules on arm/arm64

Loading

@ALTree ALTree added this to the Go1.18 milestone Sep 20, 2021
@gopherbot gopherbot closed this in 79159f2 Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants