Go version

go version go1.25.0 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/usr/local/google/home/shaojunyang/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/usr/local/google/home/shaojunyang/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3974812864=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/usr/local/google/home/shaojunyang/work/misc/bce/go.mod'
GOMODCACHE='/usr/local/google/home/shaojunyang/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/google/home/shaojunyang/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/google/home/shaojunyang/work/misc/bce/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/usr/local/google/home/shaojunyang/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/google/home/shaojunyang/work/misc/bce/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Compiled this program with GOSSAFUNC=addSlice go build .

package adder

//go:noinline
func addArr(a, b [4]uint64) uint64 {
    var sum uint64
    for i := range 4 {
        sum += a[i] + b[i]
    }
    return sum
}

func addSlice(a, b []uint64) uint64 {
    var sum uint64
    if len(a) == len(b) {
        if len(a) > 4 {
            sum += addArr(([4]uint64)(a), ([4]uint64)(a))
            a = a[4:]
            b = b[4:]
        }
        for i := range len(a) {
            sum += a[i] + b[i]
        }
    }
    return sum
}

What did you see happen?

The for loop in addSlice has a bound check generated for indexing b.

What did you expect to see?

I am expecting the compiler won't generate any bound-checks for function addSlice.

It would be great if the prove pass can correctly reason about sub-slicing operations and propagate the equality through the control-flow correctly.

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: gopherbot

Change https://go.dev/cl/699155 mentions this issue: cmd/compile: eliminate bound check for slices of the same length