-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: prove/BCE don't seem affected by hints that signed integers are not negative #28956
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
Comments
Same as #28885? |
Indeed looks like it :) thanks for pointing that out. |
@blobdon is looking into this issue, and he believes that this case is simpler than some of the cases listed in #28885; for now, I'm reopening this issue for him to experiment with the simple case. Edit: it appears I can't assign issues to people ooutside the golang organisation. |
Change https://golang.org/cl/161437 mentions this issue: |
Change https://golang.org/cl/161437 fixes this issue. |
Prove currently fails to remove bounds checks of the form: if i >= 0 { // hint that i is non-negative for i < len(data) { // i becomes Phi in the loop SSA _ = data[i] // data[Phi]; bounds check!! i++ } } addIndVarRestrictions fails to identify that the loop induction variable, (Phi), is non-negative. As a result, the restrictions, i <= Phi < len(data), are only added for the signed domain. When testing the bounds check, addBranchRestrictions is similarly unable to infer that Phi is non-negative. As a result, the restriction, Phi >= len(data), is only added/tested for the unsigned domain. This CL changes the isNonNegative method to utilise the factTable's partially ordered set (poset). It also adds field factTable.zero to allow isNonNegative to query the poset using the zero(0) constant found or created early in prove. Fixes golang#28956 Change-Id: I792f886c652eeaa339b0d57d5faefbf5922fe44f
If we make the index an unsigned integer instead of using the
if i >= 0
hint, the bounds check goes away.I haven't found this in real code, but I tried this hint while trying to remove a bounds check from real code. I was surprised to see that BCE would still not do its thing with the hint. Seems to me like this should be a simple fix somewhere in the prove or BCE passes.
/cc @aclements @rasky
The text was updated successfully, but these errors were encountered: