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: unnecessary bounds checks are not removed #14808

Open
brtzsnr opened this issue Mar 13, 2016 · 5 comments
Open

cmd/compile: unnecessary bounds checks are not removed #14808

brtzsnr opened this issue Mar 13, 2016 · 5 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@brtzsnr
Copy link
Contributor

brtzsnr commented Mar 13, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version devel +8ec8017 Sun Mar 13 22:12:01 2016 +0000 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
  3. What did you do?
  4. What did you expect to see?
  5. What did you see instead?

I composed a list of bounds checks that the compiler at tip can and cannot eliminate. For some I provided an alternative implementation.

@gopherbot
Copy link

CL https://golang.org/cl/20654 mentions this issue.

@btracey
Copy link
Contributor

btracey commented Mar 17, 2016

Is this a duplicate of #5364 ? Both seem like tracking issues.

gopherbot pushed a commit that referenced this issue Mar 17, 2016
* This the simplest solution I could came up with
that doesn't required changing the compiler.
* The bound checks become constants now
so they are removed during opt phase.

Updates #14808

Change-Id: If32c33d7ec08bb400321b465015d152f0a5d3001
Reviewed-on: https://go-review.googlesource.com/20654
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2016
@martisch
Copy link
Contributor

A case that maybe could be added to the doc above and loopbce.go is when writing to an array/slice from back to front e.g. for integer formatting:

for i = len(buf) - 1; i >= 0; i-- {
    if u < 10 {
        buf[i] = byte('0' + u)
        break
    }
    next := u / 10
    buf[i] = byte('0' + u - next*10)
    u = next
}

This currently generates bounds checks but when writing the above with i = 0; i < len(buf); i++ the bounds checks are removed.

@seebs
Copy link
Contributor

seebs commented Oct 26, 2018

https://play.golang.org/p/epAcCz9W-Uu
=>
https://godbolt.org/z/vl_rTS

If you have four slice indexing operations in a single expression, with constant indexes, it should be possible to combine them.

@gopherbot
Copy link

Change https://golang.org/cl/202517 mentions this issue: encoding/binary: removal of unnecessary boundary checks.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

6 participants