-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: bounds check elimination for if len(x) > 32 { ...; x = x[8:]; ... }
#24876
Comments
This is already fixed on master by my prove CLs. I will add a specific testcase. |
Change https://golang.org/cl/107355 mentions this issue: |
Sweet! Sorry I didn't check against tip. I forgot about filing this issue and Austin's comments made it sound like it was unlikely to be done anytime soon. |
Sorry, forgot to update this issue. The specific case in dgryski/go-metro@1308eab is unfortunately not fixed yet. IOW, this still has bound checks: for len(data) >= 32 {
x += binary.BigEndian.Uint64(data)
data = data[8:]
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
data = data[8:]
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
data = data[8:]
x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$"
data = data[8:]
} while this doesn't: for len(data) >= 32 {
x += binary.BigEndian.Uint64(data[:8])
x += binary.BigEndian.Uint64(data[8:16])
x += binary.BigEndian.Uint64(data[16:24])
x += binary.BigEndian.Uint64(data[24:32])
data = data[32:]
} I'll notice that, even if you remove bound checks from the first snippet, you still get a lot of overhead compared to the second one because the additional 3 slice updates that require a writebarrier and computation of len/cap which are not optimized away. |
This is still not fixed, the testcase reflects that there are still a few boundchecks. Let's fix the good alternative with an explicit test though. Updates #24876 Change-Id: I4da35eb353e19052bd7b69ea6190a69ced8b9b3d Reviewed-on: https://go-review.googlesource.com/107355 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Giovanni Bajo <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Change https://golang.org/cl/190657 mentions this issue: |
Change https://golang.org/cl/193839 mentions this issue: |
Change https://golang.org/cl/193838 mentions this issue: |
And interesing thing I noticed when looking to fix this. Maybe it was obvious, but not to me. The bounds checks in question are not actually from the slicing operations, they are from the inlined encoding/binary methods. Within prove, the bounds check in the inlined method is actually doing some work in helping to pass information along about the length of the slice. For illustration, despite removing the bounds checks in the example for this issue, my CL above doesnt remove the IsSliceInBounds from this:
The next CL in the chain will get these though. |
Related #28941. |
( From #23354 (comment) )
In dgryski/go-metro@1308eab I got a major performance boost by changing the loop to remove the reassignments to ptr which, even though they were still within range, invalidated the bounds checks for that were valid for ptr before the assignment.
The bounds-check elimination prover should handle this common case.
The text was updated successfully, but these errors were encountered: