Skip to content

Commit cbcb031

Browse files
committed
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 golang#37608 Change-Id: I630a4e07c92297c46d18aea69ec29852d6371ff0 Reviewed-on: https://go-review.googlesource.com/c/go/+/222919 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 4ad643d commit cbcb031

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

src/cmd/compile/internal/ssa/shortcircuit.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ func shortcircuitBlock(b *Block) bool {
105105
// Track the negations so that we can swap successors as needed later.
106106
ctl := b.Controls[0]
107107
nval := 1 // the control value
108-
swap := false
108+
var swap int64
109109
for ctl.Uses == 1 && ctl.Block == b && (ctl.Op == OpCopy || ctl.Op == OpNot) {
110110
if ctl.Op == OpNot {
111-
swap = !swap
111+
swap = 1 ^ swap
112112
}
113113
ctl = ctl.Args[0]
114114
nval++ // wrapper around control value
@@ -129,25 +129,19 @@ func shortcircuitBlock(b *Block) bool {
129129
return false
130130
}
131131

132-
a := ctl.Args[cidx]
133-
// The predecessor we come in from.
134-
e1 := b.Preds[cidx]
135-
p := e1.b
136-
pi := e1.i
132+
// p is the predecessor corresponding to cidx.
133+
pe := b.Preds[cidx]
134+
p := pe.b
135+
pi := pe.i
137136

138-
// The successor we always go to when coming in
139-
// from that predecessor.
140-
si := 1 - a.AuxInt
141-
if swap {
142-
si = 1 - si
143-
}
144-
e2 := b.Succs[si]
145-
t := e2.b
137+
// t is the "taken" branch: the successor we always go to when coming in from p.
138+
ti := 1 ^ ctl.Args[cidx].AuxInt ^ swap
139+
te := b.Succs[ti]
140+
t := te.b
146141
if p == b || t == b {
147142
// This is an infinite loop; we can't remove it. See issue 33903.
148143
return false
149144
}
150-
ti := e2.i
151145

152146
// We're committed. Update CFG and Phis.
153147

@@ -164,11 +158,11 @@ func shortcircuitBlock(b *Block) bool {
164158

165159
// Fix up t to have one more predecessor.
166160
t.Preds = append(t.Preds, Edge{p, pi})
167-
for _, w := range t.Values {
168-
if w.Op != OpPhi {
161+
for _, v := range t.Values {
162+
if v.Op != OpPhi {
169163
continue
170164
}
171-
w.AddArg(w.Args[ti])
165+
v.AddArg(v.Args[te.i])
172166
}
173167

174168
if len(b.Preds) == 0 {

0 commit comments

Comments
 (0)