-
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: recognize and optimize "in range" booleans #15844
Comments
This turns out to be a real pain to do in SSA, so I added it to the frontend instead. Even the fairly simple fix there has pleasing results for package strconv, which makes heavy use of these kinds of checks, both directly and via package unicode.
This optimization is only safe for constant bounds, because if the low bound is higher than the high bound, their difference underflows. It therefore doesn't help the |
CL https://golang.org/cl/27652 mentions this issue. |
These two functions are equivalent, but the second is more efficient (it trades a subtraction for a compare-and-branch). We do this already for index-in-bounds checks. We should generally recognize integer-in-range patterns and convert them.
We should probably do this in the SSA backend, since it'll be more general and powerful there than a limited front-end rewrite like rotation recognition. (I'm open to being convinced otherwise, though.)
This will be helpful for #15780. It'll also help a bit with a hot line in scanobject (
arena_start <= obj && obj < arena_used
)./cc @brtzsnr @randall77
The text was updated successfully, but these errors were encountered: