diff options
| author | Alexander Musman <alexander.musman@gmail.com> | 2025-06-07 12:00:11 +0300 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-07-24 13:47:20 -0700 |
| commit | bd80f74bc154585237a3c1b636e30dab6d781923 (patch) | |
| tree | 27e6984202cd5192a1fe3ff5efa7f9b6b6670302 /test/codegen | |
| parent | 5c45fe1385ff30b1a138dd3dae7fc670f85dfcc9 (diff) | |
| download | go-bd80f74bc154585237a3c1b636e30dab6d781923.tar.xz | |
cmd/compile: fold shift through AND for slice operations
Fold a shift through AND when the AND gets a zero-or-one operand (e.g.
from arithmetic shift by 63 of a 64-bit value) for a common case with
slice operations:
ASR $63, R2, R2
AND R3<<3, R2, R2
ADD R2, R0, R2
As the operands are 64-bit, we can transform it to:
AND R2->63, R3, R2
ADD R2<<3, R0, R2
Code size improvement:
compile: .text: 9088004 -> 9086292 (-0.02%)
etcd: .text: 10500276 -> 10498964 (-0.01%)
Change-Id: Ibcd5e67173da39b77ceff77ca67812fb8be5a7b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/679895
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Mark Freeman <mark@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/slices.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/codegen/slices.go b/test/codegen/slices.go index 30a131a5a5..1d918a3a0a 100644 --- a/test/codegen/slices.go +++ b/test/codegen/slices.go @@ -418,6 +418,15 @@ func SliceWithSubtractBound(a []int, b int) []int { } // --------------------------------------- // +// ARM64 folding for slice masks // +// --------------------------------------- // + +func SliceAndIndex(a []int, b int) int { + // arm64:"AND\tR[0-9]+->63","ADD\tR[0-9]+<<3" + return a[b:][b] +} + +// --------------------------------------- // // Code generation for unsafe.Slice // // --------------------------------------- // |
