]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fold double negate on arm64
authorKeith Randall <khr@golang.org>
Sun, 19 Sep 2021 16:23:37 +0000 (09:23 -0700)
committerKeith Randall <khr@golang.org>
Sun, 19 Sep 2021 23:50:45 +0000 (23:50 +0000)
Fixes #48467

Change-Id: I52305dbf561ee3eee6c1f053e555a3a6ec1ab892
Reviewed-on: https://go-review.googlesource.com/c/go/+/350910
Trust: Keith Randall <khr@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
test/codegen/bits.go

index f63b2557c5cc2871a0cc29d57420d27f8fd70fb4..23ae3b12866bb6c9fc54384bd7081277ffc9feba 100644 (file)
 (XOR x (MVN y)) => (EON x y)
 (OR  x (MVN y)) => (ORN x y)
 (MVN (XOR x y)) => (EON x y)
+(NEG (NEG x)) => x
 
 (CSEL [cc] (MOVDconst [-1]) (MOVDconst [0]) flag) => (CSETM [cc] flag)
 (CSEL [cc] (MOVDconst [0]) (MOVDconst [-1]) flag) => (CSETM [arm64Negate(cc)] flag)
index 2bce96f0b26611eea9a9f43ff9afb5a46ca8cf08..661714307a7e8c7dd71927a39db520da994ba4db 100644 (file)
@@ -15691,6 +15691,16 @@ func rewriteValueARM64_OpARM64NEG(v *Value) bool {
                v.AddArg2(x, y)
                return true
        }
+       // match: (NEG (NEG x))
+       // result: x
+       for {
+               if v_0.Op != OpARM64NEG {
+                       break
+               }
+               x := v_0.Args[0]
+               v.copyOf(x)
+               return true
+       }
        // match: (NEG (MOVDconst [c]))
        // result: (MOVDconst [-c])
        for {
index 8117a623072934c4a64be3f62060965bd9769f17..8e973d5726e4b52ad4536ae65541a50392ef1df3 100644 (file)
@@ -6,6 +6,8 @@
 
 package codegen
 
+import "math/bits"
+
 /************************************
  * 64-bit instructions
  ************************************/
@@ -355,3 +357,9 @@ func issue44228b(a []int32, i int) bool {
        // amd64: "BTL", -"SHL"
        return a[i>>5]&(1<<(i&31)) != 0
 }
+
+func issue48467(x, y uint64) uint64 {
+       // arm64: -"NEG"
+       d, borrow := bits.Sub64(x, y, 0)
+       return x - d&(-borrow)
+}