]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: search for remaining WB ops from end to beginning
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 17 May 2017 13:28:03 +0000 (06:28 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 18 May 2017 20:14:12 +0000 (20:14 +0000)
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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/ssa/writebarrier.go

index 3443c6464f2ceefe40a254c98017d34e98458678..cf22724a869ce9a58c7636c1ad9e5fe31da8747a 100644 (file)
@@ -261,8 +261,11 @@ func writebarrier(f *Func) {
                }
 
                // if we have more stores in this block, do this block again
-               for _, w := range b.Values {
-                       if w.Op == OpStoreWB || w.Op == OpMoveWB || w.Op == OpZeroWB {
+               // check from end to beginning, to avoid quadratic behavior; issue 13554
+               // TODO: track the final value to avoid any looping here at all
+               for i := len(b.Values) - 1; i >= 0; i-- {
+                       switch b.Values[i].Op {
+                       case OpStoreWB, OpMoveWB, OpZeroWB:
                                goto again
                        }
                }