aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2023-08-21 10:03:07 -0700
committerKeith Randall <khr@golang.org>2023-08-21 20:52:15 +0000
commit0b47b94a6275b0d0830e5ce7a03aaa99430f7f76 (patch)
tree1602dd02a1679eb7e7f2822c60b784a532fef636 /src
parenta9bedc36a53f9d4ff6ab1c1a43c900c2fc8eba84 (diff)
downloadgo-0b47b94a6275b0d0830e5ce7a03aaa99430f7f76.tar.xz
cmd/compile: remove more extension ops when not needed
If we're not using the upper bits, don't bother issuing a sign/zero extension operation. For arm64, after CL 520916 which fixed a correctness bug with extensions but as a side effect leaves many unnecessary ones still in place. Change-Id: I5f4fe4efbf2e9f80969ab5b9a6122fb812dc2ec0 Reviewed-on: https://go-review.googlesource.com/c/go/+/521496 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ssa/_gen/ARM64.rules5
-rw-r--r--src/cmd/compile/internal/ssa/rewriteARM64.go66
2 files changed, 71 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/ARM64.rules b/src/cmd/compile/internal/ssa/_gen/ARM64.rules
index 9af771a472..4a99771e3b 100644
--- a/src/cmd/compile/internal/ssa/_gen/ARM64.rules
+++ b/src/cmd/compile/internal/ssa/_gen/ARM64.rules
@@ -1574,6 +1574,11 @@
// zero upper bit of the register; no need to zero-extend
(MOVBUreg x:((Equal|NotEqual|LessThan|LessThanU|LessThanF|LessEqual|LessEqualU|LessEqualF|GreaterThan|GreaterThanU|GreaterThanF|GreaterEqual|GreaterEqualU|GreaterEqualF) _)) => (MOVDreg x)
+// Don't bother extending if we're not using the higher bits.
+(MOV(B|BU)reg x) && v.Type.Size() <= 1 => x
+(MOV(H|HU)reg x) && v.Type.Size() <= 2 => x
+(MOV(W|WU)reg x) && v.Type.Size() <= 4 => x
+
// omit unsign extension
(MOVWUreg x) && zeroUpper32Bits(x, 3) => x
diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go
index a29eff1db5..84274bd506 100644
--- a/src/cmd/compile/internal/ssa/rewriteARM64.go
+++ b/src/cmd/compile/internal/ssa/rewriteARM64.go
@@ -8472,6 +8472,17 @@ func rewriteValueARM64_OpARM64MOVBUreg(v *Value) bool {
v.AddArg(x)
return true
}
+ // match: (MOVBUreg x)
+ // cond: v.Type.Size() <= 1
+ // result: x
+ for {
+ x := v_0
+ if !(v.Type.Size() <= 1) {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
// match: (MOVBUreg (SLLconst [lc] x))
// cond: lc >= 8
// result: (MOVDconst [0])
@@ -8735,6 +8746,17 @@ func rewriteValueARM64_OpARM64MOVBreg(v *Value) bool {
v.AuxInt = int64ToAuxInt(int64(int8(c)))
return true
}
+ // match: (MOVBreg x)
+ // cond: v.Type.Size() <= 1
+ // result: x
+ for {
+ x := v_0
+ if !(v.Type.Size() <= 1) {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
// match: (MOVBreg <t> (ANDconst x [c]))
// cond: uint64(c) & uint64(0xffffffffffffff80) == 0
// result: (ANDconst <t> x [c])
@@ -10386,6 +10408,17 @@ func rewriteValueARM64_OpARM64MOVHUreg(v *Value) bool {
v.AuxInt = int64ToAuxInt(int64(uint16(c)))
return true
}
+ // match: (MOVHUreg x)
+ // cond: v.Type.Size() <= 2
+ // result: x
+ for {
+ x := v_0
+ if !(v.Type.Size() <= 2) {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
// match: (MOVHUreg (SLLconst [lc] x))
// cond: lc >= 16
// result: (MOVDconst [0])
@@ -10832,6 +10865,17 @@ func rewriteValueARM64_OpARM64MOVHreg(v *Value) bool {
v.AuxInt = int64ToAuxInt(int64(int16(c)))
return true
}
+ // match: (MOVHreg x)
+ // cond: v.Type.Size() <= 2
+ // result: x
+ for {
+ x := v_0
+ if !(v.Type.Size() <= 2) {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
// match: (MOVHreg <t> (ANDconst x [c]))
// cond: uint64(c) & uint64(0xffffffffffff8000) == 0
// result: (ANDconst <t> x [c])
@@ -12011,6 +12055,17 @@ func rewriteValueARM64_OpARM64MOVWUreg(v *Value) bool {
return true
}
// match: (MOVWUreg x)
+ // cond: v.Type.Size() <= 4
+ // result: x
+ for {
+ x := v_0
+ if !(v.Type.Size() <= 4) {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
+ // match: (MOVWUreg x)
// cond: zeroUpper32Bits(x, 3)
// result: x
for {
@@ -12525,6 +12580,17 @@ func rewriteValueARM64_OpARM64MOVWreg(v *Value) bool {
v.AuxInt = int64ToAuxInt(int64(int32(c)))
return true
}
+ // match: (MOVWreg x)
+ // cond: v.Type.Size() <= 4
+ // result: x
+ for {
+ x := v_0
+ if !(v.Type.Size() <= 4) {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
// match: (MOVWreg <t> (ANDconst x [c]))
// cond: uint64(c) & uint64(0xffffffff80000000) == 0
// result: (ANDconst <t> x [c])