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 · 4 comments

Comments

Projects
None yet
6 participants
@brtzsnr
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

This comment has been minimized.

gopherbot commented Mar 13, 2016

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

@btracey

This comment has been minimized.

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

encoding/binary: remove bound checks from conversions.
* 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 the Performance label Apr 9, 2016

@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2016

@martisch

This comment has been minimized.

Member

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

This comment has been minimized.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment