Skip to content

Commit 85b2940

Browse files
committed
cmd/compile: search for remaining WB ops from end to beginning
The writebarrier pass processes WB ops from beginning to end, replacing them by other values. But it also checks whether there are more ops to process by walking from beginning to end. This is quadratic, so walk from end to beginning instead. This speeds up compiling the code in issue 13554: name old time/op new time/op delta Pkg 11.9s ± 2% 8.3s ± 3% -29.88% (p=0.000 n=18+17) Updates #13554 Passes toolstash-check. Change-Id: I5f8a872ddc4b783540220d89ea2ee188a6d2b2ff Reviewed-on: https://go-review.googlesource.com/43571 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 638ebb0 commit 85b2940

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,11 @@ func writebarrier(f *Func) {
261261
}
262262

263263
// if we have more stores in this block, do this block again
264-
for _, w := range b.Values {
265-
if w.Op == OpStoreWB || w.Op == OpMoveWB || w.Op == OpZeroWB {
264+
// check from end to beginning, to avoid quadratic behavior; issue 13554
265+
// TODO: track the final value to avoid any looping here at all
266+
for i := len(b.Values) - 1; i >= 0; i-- {
267+
switch b.Values[i].Op {
268+
case OpStoreWB, OpMoveWB, OpZeroWB:
266269
goto again
267270
}
268271
}

0 commit comments

Comments
 (0)