diff options
| author | Alexander Musman <alexander.musman@gmail.com> | 2025-06-07 13:18:58 +0300 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-07-24 12:39:53 -0700 |
| commit | dcb479c2f9e6c379ee01efb3b1fa8a4e784f8503 (patch) | |
| tree | b089e32e97a9987491067c959c960c7e773a81c4 /test/codegen | |
| parent | f11599b0b909a61d575bcea532ee2250f9a682da (diff) | |
| download | go-dcb479c2f9e6c379ee01efb3b1fa8a4e784f8503.tar.xz | |
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>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/slices.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/codegen/slices.go b/test/codegen/slices.go index 9e8990c586..30a131a5a5 100644 --- a/test/codegen/slices.go +++ b/test/codegen/slices.go @@ -429,3 +429,21 @@ func Slice0(p *struct{}, i int) []struct{} { // amd64:-"MULQ" return unsafe.Slice(p, i) } + +// --------------------------------------- // +// Code generation for slice bounds // +// checking comparison // +// --------------------------------------- // + +func SlicePut(a []byte, c uint8) []byte { + // arm64:`CBZ\tR1` + a[0] = c + // arm64:`CMP\t\$1, R1` + a = a[1:] + a[0] = c + // arm64:`CMP\t\$2, R1` + a = a[1:] + a[0] = c + a = a[1:] + return a +} |
