cmd/compile: add anchored version of SP

The SPanchored opcode is identical to SP, except that it takes a memory
argument so that it (and more importantly, anything that uses it)
must be scheduled at or after that memory argument.

This opcode ensures that a LEAQ of a variable gets scheduled after the
corresponding VARDEF for that variable.

This may lead to less CSE of LEAQ operations. The effect is very small.
The go binary is only 80 bytes bigger after this CL. Usually LEAQs get
folded into load/store operations, so the effect is only for pointerful
types, large enough to need a duffzero, and have their address passed
somewhere. Even then, usually the CSEd LEAQs will be un-CSEd because
the two uses are on different sides of a function call and the LEAQ
ends up being rematerialized at the second use anyway.

Change-Id: Ib893562cd05369b91dd563b48fb83f5250950293
Reviewed-on: https://go-review.googlesource.com/c/go/+/452916
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Martin Möhrmann <martin@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Keith Randall 2022-11-21 22:22:36 -08:00 committed by Keith Randall
parent 47a0d46716
commit f959fb3872
29 changed files with 395 additions and 52 deletions

View file

@ -1607,17 +1607,44 @@ func rewriteValueRISCV64_OpLoad(v *Value) bool {
return false
}
func rewriteValueRISCV64_OpLocalAddr(v *Value) bool {
v_1 := v.Args[1]
v_0 := v.Args[0]
// match: (LocalAddr {sym} base _)
// result: (MOVaddr {sym} base)
b := v.Block
typ := &b.Func.Config.Types
// match: (LocalAddr <t> {sym} base mem)
// cond: t.Elem().HasPointers()
// result: (MOVaddr {sym} (SPanchored base mem))
for {
t := v.Type
sym := auxToSym(v.Aux)
base := v_0
mem := v_1
if !(t.Elem().HasPointers()) {
break
}
v.reset(OpRISCV64MOVaddr)
v.Aux = symToAux(sym)
v0 := b.NewValue0(v.Pos, OpSPanchored, typ.Uintptr)
v0.AddArg2(base, mem)
v.AddArg(v0)
return true
}
// match: (LocalAddr <t> {sym} base _)
// cond: !t.Elem().HasPointers()
// result: (MOVaddr {sym} base)
for {
t := v.Type
sym := auxToSym(v.Aux)
base := v_0
if !(!t.Elem().HasPointers()) {
break
}
v.reset(OpRISCV64MOVaddr)
v.Aux = symToAux(sym)
v.AddArg(base)
return true
}
return false
}
func rewriteValueRISCV64_OpLsh16x16(v *Value) bool {
v_1 := v.Args[1]