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: missing BCE case #41335

Open
choleraehyq opened this issue Sep 11, 2020 · 1 comment
Open

cmd/compile: missing BCE case #41335

choleraehyq opened this issue Sep 11, 2020 · 1 comment

Comments

@choleraehyq
Copy link
Contributor

@choleraehyq choleraehyq commented Sep 11, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cholerae/Library/Caches/go-build"
GOENV="/Users/cholerae/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/cholerae/Documents/gopath/pkg/mod"
GONOPROXY="code.byted.org,git.byted.org"
GONOSUMDB="code.byted.org,git.byted.org"
GOOS="darwin"
GOPATH="/Users/cholerae/Documents/gopath"
GOPRIVATE="code.byted.org,git.byted.org"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/cholerae/Documents/gopath/go"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/Users/cholerae/Documents/gopath/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

https://godbolt.org/z/31M9no

package main

//go:noinline
func test(val uint, dst []byte) byte {
    if val+3 > val {
        _ = dst[val+3]
        dst[val] = 1
        dst[val+1] = 1
        dst[val+2] = 1
        dst[val+3] = 1
    }
    return 1
}

func main() {
    println(test(100, make([]byte, 10)))
}

Bound checks in function test after _ = dst[val+3] could be eliminated, but not.

What did you expect to see?

Only one bound check exists in function test.

What did you see instead?

There are three bound checks in function test.

@ALTree ALTree added this to the Unplanned milestone Sep 14, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 20, 2020

FYI, you can write that if body as:

t := dst[val : val+4]
t[0] = 1
t[1] = 1
t[2] = 1
t[3] = 1

and then there will be no bounds checks for the individual assignments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.