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: BCE not clever enough or intended? #16813

Closed
yaxinlx opened this issue Aug 21, 2016 · 3 comments
Closed

cmd/compile: BCE not clever enough or intended? #16813

yaxinlx opened this issue Aug 21, 2016 · 3 comments

Comments

@yaxinlx
Copy link

yaxinlx commented Aug 21, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go1.7
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64
  3. What did you do?
// example4.go
package main

import "math/rand"

func fa2() {
    s := []int{0, 1, 2, 3, 4, 5, 6}
    index := rand.Intn(7)
    _ = s[index:] // line 9: bounds check 
    _ = s[:index] // line 10: bounds check eliminatd!
}

func fb2(s []int, index int) {
    _ = s[index:] // line 14: bounds check
    _ = s[:index] // line 15: bounds check // not clever enough?
}

func fc2() {
    s := []int{0, 1, 2, 3, 4, 5, 6}
    s = s[:4]
    index := rand.Intn(7)
    _ = s[index:] // line 22: bounds check 
    _ = s[:index] // line 23: bounds check eliminatd!
}

func main() {}

go build -gcflags="-d=ssa/check_bce/debug=1" example4.go
# command-line-arguments
./11.go:9: Found IsSliceInBounds
./11.go:14: Found IsSliceInBounds
./11.go:15: Found IsSliceInBounds
./11.go:22: Found IsSliceInBounds
  1. What did you expect to see?

BCE should also applied for line 15.

  1. What did you see instead?

BCE is not applied for line 15.

@josharian josharian changed the title BCE not clever enough or intended? cmd/compile: BCE not clever enough or intended? Aug 21, 2016
@josharian
Copy link
Contributor

cc @brtzsnr

@josharian josharian added this to the Unplanned milestone Aug 21, 2016
@brtzsnr
Copy link
Contributor

brtzsnr commented Aug 22, 2016

Thanks for reporting. Definitely not smart enough:

v10 = SliceLen <int> v6
v11 = SliceCap <int> v6
v12 = IsSliceInBounds <bool> v7 v10
v32 = IsSliceInBounds <bool> v7 v11

Implication v12 -> v32 is not seen by the prove pass. This is a shortcoming of the current algorithm.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/33633 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants