From: Josh Bleecher Snyder Date: Sun, 23 Apr 2017 12:03:11 +0000 (-0700) Subject: cmd/compile: lazily create true and false Values in shortcircuit X-Git-Tag: go1.9beta1~519 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=79e5ef293545dd4f96b10e0bf82582e5dd57757a;p=gostls13.git cmd/compile: lazily create true and false Values in shortcircuit It is mildly wasteful to always create values that must sometimes then be dead code eliminated. Given that it is very easy to avoid, do so. Noticed when examining a package with thousands of generated wrappers, each of which uses only a handful of Values to compile. Change-Id: If02eb4aa786dfa20f7aa43e8d729dad8b3db2786 Reviewed-on: https://go-review.googlesource.com/41502 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/compile/internal/ssa/shortcircuit.go b/src/cmd/compile/internal/ssa/shortcircuit.go index 54e186980d..506be4e7a0 100644 --- a/src/cmd/compile/internal/ssa/shortcircuit.go +++ b/src/cmd/compile/internal/ssa/shortcircuit.go @@ -17,8 +17,7 @@ func shortcircuit(f *Func) { // x = phi(a, ...) // // We can replace the "a" in the phi with the constant true. - ct := f.ConstBool(f.Entry.Pos, f.Config.Types.Bool, true) - cf := f.ConstBool(f.Entry.Pos, f.Config.Types.Bool, false) + var ct, cf *Value for _, b := range f.Blocks { for _, v := range b.Values { if v.Op != OpPhi { @@ -37,8 +36,14 @@ func shortcircuit(f *Func) { continue } if e.i == 0 { + if ct == nil { + ct = f.ConstBool(f.Entry.Pos, f.Config.Types.Bool, true) + } v.SetArg(i, ct) } else { + if cf == nil { + cf = f.ConstBool(f.Entry.Pos, f.Config.Types.Bool, false) + } v.SetArg(i, cf) } }