]> Cypherpunks repositories - gostls13.git/commit
runtime: add explicit lower bounds check to decoderune
authorJonah Uellenberg <JonahUellenberg@gmail.com>
Fri, 6 Feb 2026 02:48:07 +0000 (02:48 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 6 Feb 2026 17:40:28 +0000 (09:40 -0800)
commitbd7b8a52c847afcfc15b21741ec8972275a79c34
tree53de07a77f8c0593f9213b238febe3e38a582f5f
parent5f51b092846ae43d03092d866449d9933a8bf42b
runtime: add explicit lower bounds check to decoderune

decoderune is only called by generated code, so we can guarantee that
it's non-negative. This allows eliminating the automatic bounds check in
it.

To make this work, we need to expand the existing optimization to uints.
This generally enables BCE for cases like this:
```go
func test(list []int, idx uint64) int {
        if idx >= uint64(len(list)) {
                return 0
        }

        list1 := list[idx:]
        return list1[0]
}
```

Change-Id: I86a51b26ca0e63522dec99f7d6efe6bdcd2d6487
GitHub-Last-Rev: 82d44e0a080b53ee02c31ee1f92a8a0acd8d2621
GitHub-Pull-Request: golang/go#76610
Reviewed-on: https://go-review.googlesource.com/c/go/+/725101
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/prove.go
src/cmd/compile/internal/walk/range.go
src/runtime/utf8.go