Skip to content

Commit 13bda0e

Browse files
randall77heschi
authored andcommitted
[release-branch.go1.18] cmd/compile: disable rewrite loop detector for deadcode-only changes
We're guaranteed we won't infinite loop on deadcode-only changes, because each change converts valid -> invalid, and there are only a finite number of valid values. The loops this test is looking for are those generated by rule applications, so it isn't useful to check for loops when rules aren't involved. Fixes #52366 Change-Id: Idf1abeab9d47baafddc3a1197d5064faaf07ef78 Reviewed-on: https://go-review.googlesource.com/c/go/+/392760 Trust: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]> Trust: Josh Bleecher Snyder <[email protected]> (cherry picked from commit 15728ce) Reviewed-on: https://go-review.googlesource.com/c/go/+/400514 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 0287895 commit 13bda0e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
4040
var states map[string]bool
4141
for {
4242
change := false
43+
deadChange := false
4344
for _, b := range f.Blocks {
4445
var b0 *Block
4546
if debug > 1 {
@@ -73,7 +74,7 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
7374
// Not quite a deadcode pass, because it does not handle cycles.
7475
// But it should help Uses==1 rules to fire.
7576
v.reset(OpInvalid)
76-
change = true
77+
deadChange = true
7778
}
7879
// No point rewriting values which aren't used.
7980
continue
@@ -145,15 +146,16 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
145146
}
146147
}
147148
}
148-
if !change {
149+
if !change && !deadChange {
149150
break
150151
}
151152
iters++
152-
if iters > 1000 || debug >= 2 {
153+
if (iters > 1000 || debug >= 2) && change {
153154
// We've done a suspiciously large number of rewrites (or we're in debug mode).
154155
// As of Sep 2021, 90% of rewrites complete in 4 iterations or fewer
155156
// and the maximum value encountered during make.bash is 12.
156157
// Start checking for cycles. (This is too expensive to do routinely.)
158+
// Note: we avoid this path for deadChange-only iterations, to fix #51639.
157159
if states == nil {
158160
states = make(map[string]bool)
159161
}

0 commit comments

Comments
 (0)