Skip to content

Commit 524946d

Browse files
committed
cmd/compile: don't preload registers if destination already scheduled
In regalloc, we allocate some values to registers before loop entry, so that they don't need to be loaded (from spill locations) during the loop. But it is pointless if we've already regalloc'd the loop body. Whatever restores we needed for the body are already generated. It's not clear if this code is ever useful. No tests fail if I just remove it. But at least this change is worthwhile. It doesn't help, and it actively inserts more restores than we really need (mostly because the desired register list is approximate - I have seen cases where the loads implicated here end up being dead because the restores hit the wrong registers and the edge shuffle pass knows it needs the restores in different registers). While we are here, might as well have layoutRegallocOrder return the standard layout order instead of recomputing it. Change-Id: Ia624d5121de59b6123492603695de50b272b277f Reviewed-on: https://go-review.googlesource.com/c/go/+/672735 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
1 parent ce88e34 commit 524946d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func layout(f *Func) {
1515
// imposed by the linear-scan algorithm.
1616
func layoutRegallocOrder(f *Func) []*Block {
1717
// remnant of an experiment; perhaps there will be another.
18-
return layoutOrder(f)
18+
return f.Blocks
1919
}
2020

2121
func layoutOrder(f *Func) []*Block {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,10 @@ func (s *regAllocState) regalloc(f *Func) {
18991899
if s.f.Config.hasGReg && s.regs[s.GReg].v != nil {
19001900
s.freeReg(s.GReg) // Spill value in G register before any merge.
19011901
}
1902+
if s.blockOrder[b.ID] > s.blockOrder[b.Succs[0].b.ID] {
1903+
// No point if we've already regalloc'd the destination.
1904+
goto badloop
1905+
}
19021906
// For this to be worthwhile, the loop must have no calls in it.
19031907
top := b.Succs[0].b
19041908
loop := s.loopnest.b2l[top.ID]

0 commit comments

Comments
 (0)