Skip to content

Commit c686783

Browse files
committed
cmd/compile/internal/ssa: delay rewrite cycle detection for huge funcs
The SSA rewrite pass has some logic that looks to see whether a suspiciously large number of rewrites is happening, and if so, turns on logic to try to detect rewrite cycles. The cycle detection logic is quite expensive (hashes the entire function), meaning that for very large functions we might get a successful compilation in a minute or two with no cycle detection, but take a couple of hours once cycle detection kicks in. This patch moves from a fixed limit of 1000 iterations to a limit set partially based on the size of the function (meaning that we'll wait longer before turning cycle detection for a large func). Fixes #66773. Change-Id: I72f8524d706f15b3f0150baf6abeab2a5d3e15c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/578215 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 076166a commit c686783

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
4040
if debug > 1 {
4141
fmt.Printf("%s: rewriting for %s\n", f.pass.name, f.Name)
4242
}
43+
// if the number of rewrite iterations reaches itersLimit we will
44+
// at that point turn on cycle detection. Instead of a fixed limit,
45+
// size the limit according to func size to allow for cases such
46+
// as the one in issue #66773.
47+
itersLimit := f.NumBlocks()
48+
if itersLimit < 20 {
49+
itersLimit = 20
50+
}
4351
var iters int
4452
var states map[string]bool
4553
for {
@@ -154,7 +162,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
154162
break
155163
}
156164
iters++
157-
if (iters > 1000 || debug >= 2) && change {
165+
if (iters > itersLimit || debug >= 2) && change {
158166
// We've done a suspiciously large number of rewrites (or we're in debug mode).
159167
// As of Sep 2021, 90% of rewrites complete in 4 iterations or fewer
160168
// and the maximum value encountered during make.bash is 12.

0 commit comments

Comments
 (0)