1
0
mirror of https://github.com/golang/go synced 2024-11-18 18:14:43 -07:00

cmd/compile: use fuse to implement shortcircuit loop

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>
This commit is contained in:
Josh Bleecher Snyder 2020-04-18 18:00:40 -07:00
parent c9af5523f3
commit 0239a5c478
2 changed files with 5 additions and 14 deletions

View 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()

View 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