]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fold ADDconsts together for PPC
authorKeith Randall <khr@golang.org>
Fri, 16 Sep 2016 19:08:05 +0000 (12:08 -0700)
committerKeith Randall <khr@golang.org>
Mon, 19 Sep 2016 15:57:29 +0000 (15:57 +0000)
Change-Id: I571f03af6f791e78e7e18addcc310eb25747cdcf
Reviewed-on: https://go-review.googlesource.com/29351
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/ssa/gen/PPC64.rules
src/cmd/compile/internal/ssa/rewritePPC64.go

index c1be4c79531a1839a28c103f5a407db247ba336e..1bf8e332a54c0cb6a976fd1ad99c241c0a84e647 100644 (file)
 
 // Optimizations
 
-(ADD (MOVDconst [c]) x) && int64(int32(c)) == c -> (ADDconst [c] x)
-(ADD x (MOVDconst [c])) && int64(int32(c)) == c -> (ADDconst [c] x)
+(ADD (MOVDconst [c]) x) && is32Bit(c) -> (ADDconst [c] x)
+(ADD x (MOVDconst [c])) && is32Bit(c) -> (ADDconst [c] x)
+(ADDconst [c] (ADDconst [d] x)) && is32Bit(c+d) -> (ADDconst [c+d] x)
 
 // Fold offsets for stores.
 (MOVDstore [off1] {sym} (ADDconst [off2] x) val mem) && is16Bit(off1+off2) -> (MOVDstore [off1+off2] {sym} x val mem)
index 1a0a0d62edd63b984f69ef5a913219714af55cb7..6a81464d4e07e2c64f6cf18de5859cf5036942f4 100644 (file)
@@ -340,6 +340,8 @@ func rewriteValuePPC64(v *Value, config *Config) bool {
                return rewriteValuePPC64_OpOrB(v, config)
        case OpPPC64ADD:
                return rewriteValuePPC64_OpPPC64ADD(v, config)
+       case OpPPC64ADDconst:
+               return rewriteValuePPC64_OpPPC64ADDconst(v, config)
        case OpPPC64CMPUconst:
                return rewriteValuePPC64_OpPPC64CMPUconst(v, config)
        case OpPPC64CMPWUconst:
@@ -3977,7 +3979,7 @@ func rewriteValuePPC64_OpPPC64ADD(v *Value, config *Config) bool {
        b := v.Block
        _ = b
        // match: (ADD (MOVDconst [c]) x)
-       // cond: int64(int32(c)) == c
+       // cond: is32Bit(c)
        // result: (ADDconst [c] x)
        for {
                v_0 := v.Args[0]
@@ -3986,7 +3988,7 @@ func rewriteValuePPC64_OpPPC64ADD(v *Value, config *Config) bool {
                }
                c := v_0.AuxInt
                x := v.Args[1]
-               if !(int64(int32(c)) == c) {
+               if !(is32Bit(c)) {
                        break
                }
                v.reset(OpPPC64ADDconst)
@@ -3995,7 +3997,7 @@ func rewriteValuePPC64_OpPPC64ADD(v *Value, config *Config) bool {
                return true
        }
        // match: (ADD x (MOVDconst [c]))
-       // cond: int64(int32(c)) == c
+       // cond: is32Bit(c)
        // result: (ADDconst [c] x)
        for {
                x := v.Args[0]
@@ -4004,7 +4006,7 @@ func rewriteValuePPC64_OpPPC64ADD(v *Value, config *Config) bool {
                        break
                }
                c := v_1.AuxInt
-               if !(int64(int32(c)) == c) {
+               if !(is32Bit(c)) {
                        break
                }
                v.reset(OpPPC64ADDconst)
@@ -4014,6 +4016,30 @@ func rewriteValuePPC64_OpPPC64ADD(v *Value, config *Config) bool {
        }
        return false
 }
+func rewriteValuePPC64_OpPPC64ADDconst(v *Value, config *Config) bool {
+       b := v.Block
+       _ = b
+       // match: (ADDconst [c] (ADDconst [d] x))
+       // cond: is32Bit(c+d)
+       // result: (ADDconst [c+d] x)
+       for {
+               c := v.AuxInt
+               v_0 := v.Args[0]
+               if v_0.Op != OpPPC64ADDconst {
+                       break
+               }
+               d := v_0.AuxInt
+               x := v_0.Args[0]
+               if !(is32Bit(c + d)) {
+                       break
+               }
+               v.reset(OpPPC64ADDconst)
+               v.AuxInt = c + d
+               v.AddArg(x)
+               return true
+       }
+       return false
+}
 func rewriteValuePPC64_OpPPC64CMPUconst(v *Value, config *Config) bool {
        b := v.Block
        _ = b