just made some tests to check the new SSA BCE feature.
It is cool by removing many unnecessary bounds checks.
But I still found some cases where I think BCE should also be applied but 
not.
I don't know if they are intended or not.

// 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 fd2(s []int) {
    for i := len(s) - 1; i >= 0; i -- {
        _ = s[i] // line 28: bounds check 
        _ = s[i:len(s)]
    }
}

func main() {}

//////////////////////////////
////
go build -gcflags="-d=ssa/check_bce/
debug=1"  11.go
# command-line-arguments
./11.go:9: Found IsSliceInBounds
./11.go:14: Found IsSliceInBounds
./11.go:15: Found IsSliceInBounds
./11.go:22: Found IsSliceInBounds
./11.go:28: Found IsInBounds

where line 15 in fb2 and line 28 in fd2 should be BCEed, I think, but not.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to