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>
fuseTypePlain fuseType = 1 << iota
fuseTypeIf
fuseTypeIntInRange
+ fuseTypeShortCircuit
)
// fuse simplifies control flow by joining basic blocks.
if typ&fuseTypePlain != 0 {
changed = fuseBlockPlain(b) || changed
}
+ if typ&fuseTypeShortCircuit != 0 {
+ changed = shortcircuitBlock(b) || changed
+ }
}
if changed {
f.invalidateCFG()
// 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