mirror of
https://github.com/golang/go
synced 2024-11-18 20:24:41 -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:
parent
c9af5523f3
commit
0239a5c478
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user