]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: optimize slice bounds checking with SUB/SUBconst comparisons
authorAlexander Musman <alexander.musman@gmail.com>
Sat, 7 Jun 2025 10:18:58 +0000 (13:18 +0300)
committerGopher Robot <gobot@golang.org>
Thu, 24 Jul 2025 19:39:53 +0000 (12:39 -0700)
commitdcb479c2f9e6c379ee01efb3b1fa8a4e784f8503
treeb089e32e97a9987491067c959c960c7e773a81c4
parentf11599b0b909a61d575bcea532ee2250f9a682da
cmd/compile: optimize slice bounds checking with SUB/SUBconst comparisons

Optimize ARM64 code generation for slice bounds checking by recognizing
patterns where comparisons to zero involve SUB or SUBconst operations.
This change adds SSA opt rules to simplify:
 (CMPconst [0] (SUB x y)) => (CMP x y)

The optimizations apply to EQ, NE, ULE, and UGT comparisons, enabling
more efficient bounds checking for slice operations.

Code size improvement:
compile: .text:    9088004  ->  9065988 (-0.24%)
etcd:    .text:    10500276 -> 10497092 (-0.03%)
Change-Id: I467cb27674351652bcacc52b87e1f19677bd46a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/679915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/_gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
test/codegen/slices.go