aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/shortcircuit.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2020-03-08 11:39:39 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2020-03-13 19:43:47 +0000
commitcbcb031fe8b26be9d40c5fbb0c1934b0afdcf422 (patch)
tree229c3a8b2c559264d3838ba4336bba1fc3be535f /src/cmd/compile/internal/ssa/shortcircuit.go
parent4ad643d2089b73fbcfc2c0e3f61cb63dcb217ec5 (diff)
downloadgo-cbcb031fe8b26be9d40c5fbb0c1934b0afdcf422.tar.gz
go-cbcb031fe8b26be9d40c5fbb0c1934b0afdcf422.zip
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>
Diffstat (limited to 'src/cmd/compile/internal/ssa/shortcircuit.go')
-rw-r--r--src/cmd/compile/internal/ssa/shortcircuit.go32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/cmd/compile/internal/ssa/shortcircuit.go b/src/cmd/compile/internal/ssa/shortcircuit.go
index 274ef9a128..cc23701c39 100644
--- a/src/cmd/compile/internal/ssa/shortcircuit.go
+++ b/src/cmd/compile/internal/ssa/shortcircuit.go
@@ -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 {