Open
Description
Go version
go version go1.22.5 linux/amd64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/tdakkota/.cache/go-build'
GOENV='/home/tdakkota/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/tdakkota/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/tdakkota/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/tdakkota/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='go1.22.5+auto'
GOTOOLDIR='/home/tdakkota/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2547774337=/tmp/go-build -gno-record-gcc-switches'
What did you do?
for i := range min(len(keys), len(values)) {
println(keys[i]) // Found IsInBounds
println(values[i]) // Found IsInBounds
}
https://go.dev/play/p/wE9DX4D3Iga
https://go.godbolt.org/z/11PYfc6x3
What did you see happen?
Bound checks are not eliminated.
What did you expect to see?
Given that min(len(x), len(y))
is non-negative and less or equal than len(x)
and len(y)
, i
is always in bounds of both slices, so bounds checks could be eliminated.
Iteration patterns like this are quite common, especially in columnar data formats.