-
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: Prove doesn't understand division of slice length #57077
Comments
Change https://go.dev/cl/455095 mentions this issue: |
This is a correct behavior. See #16595 Also see the "Example 3" section in https://go101.org/article/bounds-check-elimination.html |
Ah, it looks this is a different problem. [update] Sorry, the bounds should be eliminated here. |
I've seen your:
But I'm responding anyway for posterity and future readers. 🙂
Thoses examples you linked are different, they incorrectly assume that Here we have a different issue, actually it reproduce just like this without this double left / right reslicing: func SplitInHalfRight(s []int) (right []int) {
middle := len(s) / 2
right = s[middle:]
return
} It should BCE but it doesn't, hopefully this can convaince you, if we feed a 0 length slice in the original function we will get this after folding out all constants: func SplitInHalf(s []int) (left, right []int) {
middle := len(s) / 2 // 0 / 2 = 0
left = s[:middle] // []int{}[0:0] -> []int{}
right = s[middle:] // []int{}[0:0] -> []int{}
return
} In other words feeding an empty slice produce two empty slices. This was easy to fix, I just had to teach the compiler that for unsigned divisions |
cc @golang/compiler |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I took the length of an object, to split it into halves, and there were IsSliceInBounds checks
What did you expect to see?
The IsSliceInBounds checks eliminatied
What did you see instead?
They were not eliminated
Short program showing issue
$ go build -gcflags="-d=ssa/check_bce/debug=1" main.go
command-line-arguments
./main.go:5:10: Found IsSliceInBounds
./main.go:6:11: Found IsSliceInBounds
The text was updated successfully, but these errors were encountered: