1
0
mirror of https://github.com/golang/go synced 2024-11-23 04:20:03 -07:00

cmd/compile: add rules to avoid unnecessary MOVDaddr for PPC64

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>
This commit is contained in:
Lynn Boger 2023-09-12 09:34:43 -05:00
parent de3bae1952
commit b7e0dfc437
2 changed files with 37 additions and 0 deletions

View File

@ -238,6 +238,8 @@
(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 ...)

View 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]