]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use fuse to implement shortcircuit loop
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 19 Apr 2020 01:00:40 +0000 (18:00 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 20 Apr 2020 19:36:50 +0000 (19:36 +0000)
The rewrite loop in shortcircuit is identical to the one in fuse.
That's not surprising; shortcircuit is fuse-like.

Take advantage of that by merging the two loops.

Passes toolstash-check.

Change-Id: I642cb39a23d2ac8964ed577678f062fce721439c
Reviewed-on: https://go-review.googlesource.com/c/go/+/229003
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/fuse.go
src/cmd/compile/internal/ssa/shortcircuit.go

index f80ec0dc5d503c00e61defe06da26ba2d82fa3ee..c51461cbfffedd375ed7a8f07761d1a9d8e9f2bb 100644 (file)
@@ -20,6 +20,7 @@ const (
        fuseTypePlain fuseType = 1 << iota
        fuseTypeIf
        fuseTypeIntInRange
+       fuseTypeShortCircuit
 )
 
 // fuse simplifies control flow by joining basic blocks.
@@ -38,6 +39,9 @@ func fuse(f *Func, typ fuseType) {
                        if typ&fuseTypePlain != 0 {
                                changed = fuseBlockPlain(b) || changed
                        }
+                       if typ&fuseTypeShortCircuit != 0 {
+                               changed = shortcircuitBlock(b) || changed
+                       }
                }
                if changed {
                        f.invalidateCFG()
index 9f181170663dc9ca9bfc1c756c5248553aa922d4..c5df457c4e2e7ce1f4f10262ff89d25143564182 100644 (file)
@@ -58,20 +58,7 @@ func shortcircuit(f *Func) {
        //   if v goto t else u
        // We can redirect p to go directly to t instead of b.
        // (If v is not live after b).
-       for changed := true; changed; {
-               changed = false
-               for i := len(f.Blocks) - 1; i >= 0; i-- {
-                       b := f.Blocks[i]
-                       if fuseBlockPlain(b) {
-                               changed = true
-                               continue
-                       }
-                       changed = shortcircuitBlock(b) || changed
-               }
-               if changed {
-                       f.invalidateCFG()
-               }
-       }
+       fuse(f, fuseTypePlain|fuseTypeShortCircuit)
 }
 
 // shortcircuitBlock checks for a CFG in which an If block