Skip to content

Commit 2611f3d

Browse files
committed
remove loop rotate
1 parent 1e61a84 commit 2611f3d

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ var passes = [...]pass{
508508
{name: "late nilcheck", fn: nilcheckelim2},
509509
{name: "flagalloc", fn: flagalloc, required: true}, // allocate flags register
510510
{name: "regalloc", fn: regalloc, required: true}, // allocate int & float registers + stack slots
511-
{name: "trim", fn: trim}, // remove empty blocks
511+
{name: "loop rotate", fn: loopRotate},
512+
{name: "trim", fn: trim}, // remove empty blocks
512513
}
513514

514515
// Double-check phase ordering constraints.
@@ -576,6 +577,8 @@ var passOrder = [...]constraint{
576577
{"schedule", "flagalloc"},
577578
// regalloc needs flags to be allocated first.
578579
{"flagalloc", "regalloc"},
580+
// loopRotate will confuse regalloc.
581+
{"regalloc", "loop rotate"},
579582
// trim needs regalloc to be done first.
580583
{"regalloc", "trim"},
581584
// memcombine works better if fuse happens first, to help merge stores.

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func (g *chainGraph) getChain(b *Block) *chain {
256256

257257
// mergeChain merges the "from" chain into the "to" chain. The from chain is
258258
// removed then.
259-
func (g *chainGraph) mergeChain(to, from *chain) {
259+
func (g *chainGraph) mergeChain(from, to *chain) {
260260
for _, block := range from.blocks {
261261
g.b2chain[block.ID] = to
262262
}
@@ -321,28 +321,20 @@ func greedyBlockOrder(fn *Func) []*Block {
321321
// If the weights are the same, then keep the original order, this
322322
// ensures that adjacent edges are accessed sequentially, which has
323323
// a noticeable impact on performance
324-
return e1.weight >= e2.weight
324+
return e1.weight > e2.weight
325325
})
326326

327327
// Merge proper chains until no more chains can be merged
328328
for _, edge := range graph.edges {
329-
src := graph.getChain(edge.src)
330-
dst := graph.getChain(edge.dst)
331-
if src == dst {
332-
// Loop detected, "rotate" the loop from [..,header,body,latch] to
333-
// [..,body,latch,header]
334-
for idx, block := range src.blocks {
335-
if block == edge.dst && block.Kind != BlockPlain /*already rotated?*/ {
336-
c := append(src.blocks[0:idx], src.blocks[idx+1:]...)
337-
c = append(c, block)
338-
src.blocks = c
339-
break
340-
}
329+
c1 := graph.getChain(edge.src)
330+
c2 := graph.getChain(edge.dst)
331+
// [c1] edge [c2] ? Then merge c1 into c2 and remove entire c1 then
332+
if c1 != c2 && (edge.dst == c2.first() && edge.src == c1.last()) {
333+
if fn.pass.debug > 2 {
334+
fmt.Printf("process %v merge %v to %v\n",
335+
edge, c2.blocks, c1.blocks)
341336
}
342-
continue
343-
}
344-
if edge.dst == dst.first() && edge.src == src.last() {
345-
graph.mergeChain(src, dst)
337+
graph.mergeChain(c2, c1)
346338
}
347339
}
348340
i := 0
@@ -413,7 +405,7 @@ func greedyBlockOrder(fn *Func) []*Block {
413405
}
414406
if len(blockOrder) != len(fn.Blocks) {
415407
graph.print()
416-
fn.Fatalf("miss blocks in final order")
408+
fn.Fatalf("miss blocks in final order: %v %v", blockOrder, fn.Blocks)
417409
}
418410
if entryChain := graph.getChain(fn.Entry); entryChain != graph.chains[0] ||
419411
entryChain.first() != fn.Entry {

0 commit comments

Comments
 (0)