mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
076166ab4e
commit
c686783cab
1 changed files with 9 additions and 1 deletions
|
|
@ -40,6 +40,14 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
|
|||
if debug > 1 {
|
||||
fmt.Printf("%s: rewriting for %s\n", f.pass.name, f.Name)
|
||||
}
|
||||
// if the number of rewrite iterations reaches itersLimit we will
|
||||
// at that point turn on cycle detection. Instead of a fixed limit,
|
||||
// size the limit according to func size to allow for cases such
|
||||
// as the one in issue #66773.
|
||||
itersLimit := f.NumBlocks()
|
||||
if itersLimit < 20 {
|
||||
itersLimit = 20
|
||||
}
|
||||
var iters int
|
||||
var states map[string]bool
|
||||
for {
|
||||
|
|
@ -154,7 +162,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
|
|||
break
|
||||
}
|
||||
iters++
|
||||
if (iters > 1000 || debug >= 2) && change {
|
||||
if (iters > itersLimit || debug >= 2) && change {
|
||||
// We've done a suspiciously large number of rewrites (or we're in debug mode).
|
||||
// As of Sep 2021, 90% of rewrites complete in 4 iterations or fewer
|
||||
// and the maximum value encountered during make.bash is 12.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue