]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fold shift through AND for slice operations
authorAlexander Musman <alexander.musman@gmail.com>
Sat, 7 Jun 2025 09:00:11 +0000 (12:00 +0300)
committerGopher Robot <gobot@golang.org>
Thu, 24 Jul 2025 20:47:20 +0000 (13:47 -0700)
commitbd80f74bc154585237a3c1b636e30dab6d781923
tree27e6984202cd5192a1fe3ff5efa7f9b6b6670302
parent5c45fe1385ff30b1a138dd3dae7fc670f85dfcc9
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>
src/cmd/compile/internal/ssa/_gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
test/codegen/slices.go