Skip to content

Commit 56af34f

Browse files
committed
cmd/compile: place reg spills after OpArg{Int,Float}Reg ops
Tweak the register allocator to maintain the invariant that OpArg{Int,Float}Reg values are placed together at the start of the entry block, before any other non-pseudo-op values. Without this change, when the register allocator adds spills we can wind up with an interleaving of OpArg*Reg and stores, which complicates debug location analysis. Updates #40724. Change-Id: Icf30dd814a9e25263ecbea2e48feb840a6e7f2bd Reviewed-on: https://go-review.googlesource.com/c/go/+/322630 Trust: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent db66e9e commit 56af34f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cmd/compile/internal/ssa/regalloc.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,10 @@ func (s *regAllocState) placeSpills() {
18821882
phiRegs[b.ID] = m
18831883
}
18841884

1885+
mustBeFirst := func(op Op) bool {
1886+
return op.isLoweredGetClosurePtr() || op == OpPhi || op == OpArgIntReg || op == OpArgFloatReg
1887+
}
1888+
18851889
// Start maps block IDs to the list of spills
18861890
// that go at the start of the block (but after any phis).
18871891
start := map[ID][]*Value{}
@@ -1971,7 +1975,7 @@ func (s *regAllocState) placeSpills() {
19711975
// Put the spill in the best block we found.
19721976
spill.Block = best
19731977
spill.AddArg(bestArg)
1974-
if best == v.Block && v.Op != OpPhi {
1978+
if best == v.Block && !mustBeFirst(v.Op) {
19751979
// Place immediately after v.
19761980
after[v.ID] = append(after[v.ID], spill)
19771981
} else {
@@ -1983,15 +1987,15 @@ func (s *regAllocState) placeSpills() {
19831987
// Insert spill instructions into the block schedules.
19841988
var oldSched []*Value
19851989
for _, b := range s.visitOrder {
1986-
nphi := 0
1990+
nfirst := 0
19871991
for _, v := range b.Values {
1988-
if v.Op != OpPhi {
1992+
if !mustBeFirst(v.Op) {
19891993
break
19901994
}
1991-
nphi++
1995+
nfirst++
19921996
}
1993-
oldSched = append(oldSched[:0], b.Values[nphi:]...)
1994-
b.Values = b.Values[:nphi]
1997+
oldSched = append(oldSched[:0], b.Values[nfirst:]...)
1998+
b.Values = b.Values[:nfirst]
19951999
b.Values = append(b.Values, start[b.ID]...)
19962000
for _, v := range oldSched {
19972001
b.Values = append(b.Values, v)

0 commit comments

Comments
 (0)