cmd/compile: more minor cleanup in shortcircuitBlock

Continue to simplify, rename for clarity,
improve docs, and reduce variable scope.

This is in preparation for this function becoming
more complicated.

Passes toolstash-check.

Updates #37608

Change-Id: I630a4e07c92297c46d18aea69ec29852d6371ff0
Reviewed-on: https://go-review.googlesource.com/c/go/+/222919
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-03-08 11:39:39 -07:00
parent 4ad643d208
commit cbcb031fe8
1 changed files with 13 additions and 19 deletions

View File

@ -105,10 +105,10 @@ func shortcircuitBlock(b *Block) bool {
// Track the negations so that we can swap successors as needed later.
ctl := b.Controls[0]
nval := 1 // the control value
swap := false
var swap int64
for ctl.Uses == 1 && ctl.Block == b && (ctl.Op == OpCopy || ctl.Op == OpNot) {
if ctl.Op == OpNot {
swap = !swap
swap = 1 ^ swap
}
ctl = ctl.Args[0]
nval++ // wrapper around control value
@ -129,25 +129,19 @@ func shortcircuitBlock(b *Block) bool {
return false
}
a := ctl.Args[cidx]
// The predecessor we come in from.
e1 := b.Preds[cidx]
p := e1.b
pi := e1.i
// p is the predecessor corresponding to cidx.
pe := b.Preds[cidx]
p := pe.b
pi := pe.i
// The successor we always go to when coming in
// from that predecessor.
si := 1 - a.AuxInt
if swap {
si = 1 - si
}
e2 := b.Succs[si]
t := e2.b
// t is the "taken" branch: the successor we always go to when coming in from p.
ti := 1 ^ ctl.Args[cidx].AuxInt ^ swap
te := b.Succs[ti]
t := te.b
if p == b || t == b {
// This is an infinite loop; we can't remove it. See issue 33903.
return false
}
ti := e2.i
// We're committed. Update CFG and Phis.
@ -164,11 +158,11 @@ func shortcircuitBlock(b *Block) bool {
// Fix up t to have one more predecessor.
t.Preds = append(t.Preds, Edge{p, pi})
for _, w := range t.Values {
if w.Op != OpPhi {
for _, v := range t.Values {
if v.Op != OpPhi {
continue
}
w.AddArg(w.Args[ti])
v.AddArg(v.Args[te.i])
}
if len(b.Preds) == 0 {