]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssa: improve carry addition rules on PPC64
authorPaul E. Murphy <murp@ibm.com>
Fri, 8 Nov 2024 22:07:58 +0000 (16:07 -0600)
committerGopher Robot <gobot@golang.org>
Tue, 12 Nov 2024 17:40:44 +0000 (17:40 +0000)
Fold constant int16 addends for usages of math/bits.Add64(x,const,0)
on PPC64. This usage shows up in a few crypto implementations;
notably the go wrapper for CL 626176.

Change-Id: I6963163330487d04e0479b4fdac235f97bb96889
Reviewed-on: https://go-review.googlesource.com/c/go/+/625899
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/_gen/PPC64.rules
src/cmd/compile/internal/ssa/rewritePPC64.go
test/codegen/bits.go

index 8bec4895f546826b24a4929329dc652d9bc6724c..feef6ee52a9564e8406de3c220412079bcc7873f 100644 (file)
 // Fold transfer of CA -> GPR -> CA. Note 2 uses when feeding into a chained Add64carry.
 (Select1 (ADDCconst n:(ADDZEzero x) [-1])) && n.Uses <= 2 => x
 (ADDE (MOVDconst [0]) y c) => (ADDZE y c)
+(ADDC x (MOVDconst [y])) && is16Bit(y) => (ADDCconst [y] x)
 
 // Borrowing subtraction.
 (Select0 (Sub64borrow x y c)) =>                 (Select0 <typ.UInt64> (SUBE x y (Select1 <typ.UInt64> (SUBCconst c [0]))))
index 9c082c31bfe167c126357f50e86357a15b74f559..4e3b8a5cc686abf98da8a62fe864c00e834fcb68 100644 (file)
@@ -446,6 +446,8 @@ func rewriteValuePPC64(v *Value) bool {
                return true
        case OpPPC64ADD:
                return rewriteValuePPC64_OpPPC64ADD(v)
+       case OpPPC64ADDC:
+               return rewriteValuePPC64_OpPPC64ADDC(v)
        case OpPPC64ADDE:
                return rewriteValuePPC64_OpPPC64ADDE(v)
        case OpPPC64ADDconst:
@@ -4068,6 +4070,31 @@ func rewriteValuePPC64_OpPPC64ADD(v *Value) bool {
        }
        return false
 }
+func rewriteValuePPC64_OpPPC64ADDC(v *Value) bool {
+       v_1 := v.Args[1]
+       v_0 := v.Args[0]
+       // match: (ADDC x (MOVDconst [y]))
+       // cond: is16Bit(y)
+       // result: (ADDCconst [y] x)
+       for {
+               for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
+                       x := v_0
+                       if v_1.Op != OpPPC64MOVDconst {
+                               continue
+                       }
+                       y := auxIntToInt64(v_1.AuxInt)
+                       if !(is16Bit(y)) {
+                               continue
+                       }
+                       v.reset(OpPPC64ADDCconst)
+                       v.AuxInt = int64ToAuxInt(y)
+                       v.AddArg(x)
+                       return true
+               }
+               break
+       }
+       return false
+}
 func rewriteValuePPC64_OpPPC64ADDE(v *Value) bool {
        v_2 := v.Args[2]
        v_1 := v.Args[1]
index 554e363ef52119e8a38a28ca03bd5a9be31e4210..354dbf407a4bac6dc4c9d08927cf844fbd9c9ddf 100644 (file)
@@ -366,6 +366,7 @@ func issue48467(x, y uint64) uint64 {
 
 func foldConst(x, y uint64) uint64 {
        // arm64: "ADDS\t[$]7",-"MOVD\t[$]7"
+       // ppc64x: "ADDC\t[$]7,"
        d, b := bits.Add64(x, 7, 0)
        return b & d
 }