]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add rules to avoid unnecessary MOVDaddr for PPC64
authorLynn Boger <laboger@linux.vnet.ibm.com>
Tue, 12 Sep 2023 14:34:43 +0000 (09:34 -0500)
committerLynn Boger <laboger@linux.vnet.ibm.com>
Mon, 25 Sep 2023 15:24:40 +0000 (15:24 +0000)
This adds some rules to recognize MOVDaddr in those cases where
it is just adding 0 to a ptr value. Instead the ptr value can just
be used.

Change-Id: I95188defc9701165c86bbea70d14d037a9e54853
Reviewed-on: https://go-review.googlesource.com/c/go/+/527698
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Paul Murphy <murp@ibm.com>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/compile/internal/ssa/_gen/PPC64.rules
src/cmd/compile/internal/ssa/rewritePPC64.go

index 4c4f7c8c17cb00ead54d9059cb69610136873db3..c5309f16c6fe59734fdd86a4c86fa3296408f19a 100644 (file)
 (LocalAddr <t> {sym} base mem) && t.Elem().HasPointers() => (MOVDaddr {sym} (SPanchored base mem))
 (LocalAddr <t> {sym} base _)  && !t.Elem().HasPointers() => (MOVDaddr {sym} base)
 (OffPtr [off] ptr) => (ADD (MOVDconst <typ.Int64> [off]) ptr)
+(MOVDaddr {sym} [n] p:(ADD x y)) && sym == nil && n == 0 => p
+(MOVDaddr {sym} [n] ptr) && sym == nil && n == 0 && (ptr.Op == OpArgIntReg || ptr.Op == OpPhi) => ptr
 
 // TODO: optimize these cases?
 (Ctz32NonZero ...) => (Ctz32 ...)
index 2bcc27fbc83908c66c5faf6445f2d7bde2113b8c..089e4e614ca5b5d25894d60db510bc5dadf8a7d3 100644 (file)
@@ -533,6 +533,8 @@ func rewriteValuePPC64(v *Value) bool {
                return rewriteValuePPC64_OpPPC64MOVBstoreidx(v)
        case OpPPC64MOVBstorezero:
                return rewriteValuePPC64_OpPPC64MOVBstorezero(v)
+       case OpPPC64MOVDaddr:
+               return rewriteValuePPC64_OpPPC64MOVDaddr(v)
        case OpPPC64MOVDload:
                return rewriteValuePPC64_OpPPC64MOVDload(v)
        case OpPPC64MOVDloadidx:
@@ -7778,6 +7780,39 @@ func rewriteValuePPC64_OpPPC64MOVBstorezero(v *Value) bool {
        }
        return false
 }
+func rewriteValuePPC64_OpPPC64MOVDaddr(v *Value) bool {
+       v_0 := v.Args[0]
+       // match: (MOVDaddr {sym} [n] p:(ADD x y))
+       // cond: sym == nil && n == 0
+       // result: p
+       for {
+               n := auxIntToInt32(v.AuxInt)
+               sym := auxToSym(v.Aux)
+               p := v_0
+               if p.Op != OpPPC64ADD {
+                       break
+               }
+               if !(sym == nil && n == 0) {
+                       break
+               }
+               v.copyOf(p)
+               return true
+       }
+       // match: (MOVDaddr {sym} [n] ptr)
+       // cond: sym == nil && n == 0 && (ptr.Op == OpArgIntReg || ptr.Op == OpPhi)
+       // result: ptr
+       for {
+               n := auxIntToInt32(v.AuxInt)
+               sym := auxToSym(v.Aux)
+               ptr := v_0
+               if !(sym == nil && n == 0 && (ptr.Op == OpArgIntReg || ptr.Op == OpPhi)) {
+                       break
+               }
+               v.copyOf(ptr)
+               return true
+       }
+       return false
+}
 func rewriteValuePPC64_OpPPC64MOVDload(v *Value) bool {
        v_1 := v.Args[1]
        v_0 := v.Args[0]