]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fold negation into addition/subtraction on s390x
authorJulian Zhu <jz531210@gmail.com>
Fri, 16 May 2025 17:55:12 +0000 (01:55 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 22 May 2025 01:08:51 +0000 (18:08 -0700)
Fold negation into addition/subtraction and avoid double negation.

file      before    after     Δ       %
addr2line 3909260   3909204   -56     -0.001%
asm       6714513   6714505   -8      -0.000%
buildid   3680344   3679504   -840    -0.023%
cgo       6219857   6219521   -336    -0.005%
compile   29527941  29528037  +96     +0.000%
cover     6869451   6868731   -720    -0.010%
dist      4498817   4498769   -48     -0.001%
doc       10483319  10481719  -1600   -0.015%
fix       4356204   4355932   -272    -0.006%
link      9080951   9080383   -568    -0.006%
nm        3899682   3833674   -66008  -1.693%
objdump   6347837   6347605   -232    -0.004%
pack      3103750   3103454   -296    -0.010%
pprof     18849998  18849478  -520    -0.003%
test2json 3619671   3619511   -160    -0.004%
trace     17164007  17161463  -2544   -0.015%
vet       10465861  10465173  -688    -0.007%
total     167058409 166983609 -74800  -0.045%

Change-Id: I1b8cf3939b433e1765682196b8fc1aa07d37f895
Reviewed-on: https://go-review.googlesource.com/c/go/+/673476
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/compile/internal/ssa/_gen/S390X.rules
src/cmd/compile/internal/ssa/rewriteS390X.go

index 78de5bb5a22296a239ce253003ae0f05f841a8d6..231ad0615dd96e891b141214b9a6a31d69900cce 100644 (file)
 // TODO: more of this
 (ADD x (NEG y)) => (SUB x y)
 (ADDW x (NEGW y)) => (SUBW x y)
+(SUB x (NEG y)) => (ADD x y)
+(SUBW x (NEGW y)) => (ADDW x y)
 (SUB x x) => (MOVDconst [0])
 (SUBW x x) => (MOVDconst [0])
 (AND x x) => x
 (ORW x x) => x
 (XOR x x) => (MOVDconst [0])
 (XORW x x) => (MOVDconst [0])
+(NEG (NEG x)) => x
 (NEG (ADDconst [c] (NEG x))) && c != -(1<<31) => (ADDconst [-c] x)
 (MOVBZreg (ANDWconst [m] x)) => (MOVWZreg (ANDWconst <typ.UInt32> [int32( uint8(m))] x))
 (MOVHZreg (ANDWconst [m] x)) => (MOVWZreg (ANDWconst <typ.UInt32> [int32(uint16(m))] x))
index 7e652a19bceec9686d5a945351077ca9a52d195f..2e7492501a803adef4ca0ffba5be535a5869daf1 100644 (file)
@@ -11292,6 +11292,16 @@ func rewriteValueS390X_OpS390XNEG(v *Value) bool {
                v.AuxInt = int64ToAuxInt(-c)
                return true
        }
+       // match: (NEG (NEG x))
+       // result: x
+       for {
+               if v_0.Op != OpS390XNEG {
+                       break
+               }
+               x := v_0.Args[0]
+               v.copyOf(x)
+               return true
+       }
        // match: (NEG (ADDconst [c] (NEG x)))
        // cond: c != -(1<<31)
        // result: (ADDconst [-c] x)
@@ -13326,6 +13336,18 @@ func rewriteValueS390X_OpS390XSUB(v *Value) bool {
                v.AddArg(v0)
                return true
        }
+       // match: (SUB x (NEG y))
+       // result: (ADD x y)
+       for {
+               x := v_0
+               if v_1.Op != OpS390XNEG {
+                       break
+               }
+               y := v_1.Args[0]
+               v.reset(OpS390XADD)
+               v.AddArg2(x, y)
+               return true
+       }
        // match: (SUB x x)
        // result: (MOVDconst [0])
        for {
@@ -13467,6 +13489,18 @@ func rewriteValueS390X_OpS390XSUBW(v *Value) bool {
                v.AddArg(v0)
                return true
        }
+       // match: (SUBW x (NEGW y))
+       // result: (ADDW x y)
+       for {
+               x := v_0
+               if v_1.Op != OpS390XNEGW {
+                       break
+               }
+               y := v_1.Args[0]
+               v.reset(OpS390XADDW)
+               v.AddArg2(x, y)
+               return true
+       }
        // match: (SUBW x x)
        // result: (MOVDconst [0])
        for {