]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: combine OR + NOT into ORN on PPC64
authorPaul E. Murphy <murp@ibm.com>
Tue, 3 May 2022 21:30:30 +0000 (16:30 -0500)
committerPaul Murphy <murp@ibm.com>
Wed, 4 May 2022 18:49:50 +0000 (18:49 +0000)
This shows up in a few crypto functions, and other
assorted places.

Change-Id: I5a7f4c25ddd4a6499dc295ef693b9fe43d2448ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/404057
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/ssa/gen/PPC64.rules
src/cmd/compile/internal/ssa/rewritePPC64.go
test/codegen/logic.go

index eb9fe3cf72339feb5f8d7a0ef5359290ba4c37f7..1fe7ae9e53cf4a0078cfa36b59fb813a2c68530b 100644 (file)
 (OrB ...) => (OR ...)
 (Not x) => (XORconst [1] x)
 
-// Use ANDN for AND x NOT y
+// Merge logical operations
 (AND x (NOR y y)) => (ANDN x y)
+(OR x (NOR y y)) => (ORN x y)
 
 // Lowering comparisons
 (EqB x y)  => (ANDconst [1] (EQV x y))
index 5da6d9641cee317f0ce0655b7effb0f171ba1a25..1d945be7419f16ce280f0aa40bfcbd3cc644bbb1 100644 (file)
@@ -11687,6 +11687,24 @@ func rewriteValuePPC64_OpPPC64OR(v *Value) bool {
                }
                break
        }
+       // match: (OR x (NOR y y))
+       // result: (ORN x y)
+       for {
+               for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
+                       x := v_0
+                       if v_1.Op != OpPPC64NOR {
+                               continue
+                       }
+                       y := v_1.Args[1]
+                       if y != v_1.Args[0] {
+                               continue
+                       }
+                       v.reset(OpPPC64ORN)
+                       v.AddArg2(x, y)
+                       return true
+               }
+               break
+       }
        // match: (OR (MOVDconst [c]) (MOVDconst [d]))
        // result: (MOVDconst [c|d])
        for {
index 9afdfd760fcd10f6702a2f685b63a7f68a237380..50ce5f0cca87821d685c535467ab4bbf7a80fdef 100644 (file)
@@ -22,3 +22,11 @@ func andWithUse(x, y int) int {
        // use z by returning it
        return z
 }
+
+// Verify (OR x (NOT y)) rewrites to (ORN x y) where supported
+func ornot(x, y int) int {
+       // ppc64:"ORN"
+       // ppc64le:"ORN"
+       z := x | ^y
+       return z
+}