]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: remove more extension ops when not needed
authorKeith Randall <khr@golang.org>
Mon, 21 Aug 2023 17:03:07 +0000 (10:03 -0700)
committerKeith Randall <khr@golang.org>
Mon, 21 Aug 2023 20:52:15 +0000 (20:52 +0000)
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>

src/cmd/compile/internal/ssa/_gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
test/codegen/noextend.go

index 9af771a472938b6386088cefce29ae40ab7b7f9a..4a99771e3b87585ec1e6f2f1df5d24b59fb82a95 100644 (file)
 // 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
 
index a29eff1db538284328df6ee4dec4a6e1d932a7f9..84274bd506f6cd064ea8d1a27a69c98ed7861665 100644 (file)
@@ -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])
index 61c98a796a3185e28dfdd71c8707a9d3ad6925fc..98ad0ece89db938ea51cf74b280c0a8431861d36 100644 (file)
@@ -279,3 +279,8 @@ func shouldSignEXT(x int) int64 {
        return ret
 
 }
+
+func noIntermediateExtension(a, b, c uint32) uint32 {
+       // arm64:-"MOVWU"
+       return a*b*9 + c
+}