From cbcb031fe8b26be9d40c5fbb0c1934b0afdcf422 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 8 Mar 2020 11:39:39 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/shortcircuit.go | 32 ++++++++------------ 1 file 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 { -- 2.50.0