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

brtzsnr opened this issue Mar 13, 2016 · 5 comments

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

brtzsnr opened this issue Mar 13, 2016 · 5 comments


Copy link

@brtzsnr 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)?
  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.

Copy link

@gopherbot gopherbot commented Mar 13, 2016

CL mentions this issue.

Copy link

@btracey 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-by: Russ Cox <>
Run-TryBot: Alexandru Moșoi <>
TryBot-Result: Gobot Gobot <>
@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2016
Copy link

@martisch martisch commented Apr 15, 2016

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)
    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.

Copy link

@seebs seebs commented Oct 26, 2018

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

Copy link

@gopherbot gopherbot commented Oct 21, 2019

Change mentions this issue: encoding/binary: removal of unnecessary boundary checks.

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

Successfully merging a pull request may close this issue.

None yet
6 participants