Re: [golang-dev] SSA not clever enough of intended?

281 views
Skip to first unread message

Andrew Gerrand

unread,
Aug 21, 2016, 6:59:16 PM8/21/16
to T L, golang-dev
You should send these messages to golan...@googlegroups.com, the general Go discussion list.

On 21 August 2016 at 13:31, T L <tapi...@gmail.com> wrote:
I just make some tests for 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


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

Reply all
Reply to author
Forward
0 new messages