Skip to content

Commit 40a6e2d

Browse files
committed
cmd/compile: tighten for huge functions in -N mode
Currently, in -N mode we skip the tighten pass. However, for very large functions, many values live across blocks can cause pathological behavior in the register allocator, which could use a huge amount of memory or cause the program to hang. For functions that large, debugging using a debugger is unlikely to be very useful (the function is probably generated anyway). So we do a little optimization to make fewer values live across blocks and make it easier for the compiler. Fixes #52180. Change-Id: I355fe31bb87ea5d0870bb52dd06405dd5d791dab Reviewed-on: https://go-review.googlesource.com/c/go/+/475339 Reviewed-by: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 7f38067 commit 40a6e2d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ var passes = [...]pass{
496496
{name: "checkLower", fn: checkLower, required: true},
497497
{name: "late phielim", fn: phielim},
498498
{name: "late copyelim", fn: copyelim},
499-
{name: "tighten", fn: tighten}, // move values closer to their uses
499+
{name: "tighten", fn: tighten, required: true}, // move values closer to their uses
500500
{name: "late deadcode", fn: deadcode},
501501
{name: "critical", fn: critical, required: true}, // remove critical edges
502502
{name: "phi tighten", fn: phiTighten}, // place rematerializable phi args near uses to reduce value lifetimes

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44

55
package ssa
66

7+
import "cmd/compile/internal/base"
8+
79
// tighten moves Values closer to the Blocks in which they are used.
810
// This can reduce the amount of register spilling required,
911
// if it doesn't also create more live values.
1012
// A Value can be moved to any block that
1113
// dominates all blocks in which it is used.
1214
func tighten(f *Func) {
15+
if base.Flag.N != 0 && len(f.Blocks) < 10000 {
16+
// Skip the optimization in -N mode, except for huge functions.
17+
// Too many values live across blocks can cause pathological
18+
// behavior in the register allocator (see issue 52180).
19+
return
20+
}
21+
1322
canMove := f.Cache.allocBoolSlice(f.NumValues())
1423
defer f.Cache.freeBoolSlice(canMove)
1524
for _, b := range f.Blocks {

0 commit comments

Comments
 (0)