aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/inline
diff options
context:
space:
mode:
authorzikaeroh <zikaeroh@gmail.com>2021-09-07 00:38:40 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-09-07 19:39:04 +0000
commitd92101f452e10680ad4c8af2d5ad40d940b59214 (patch)
treeafdc8794aeb7cb8dffd30eca36faf408916dea2a /src/cmd/compile/internal/inline
parent903958d2f506decf92a1bfd63dfbecadf8375735 (diff)
downloadgo-d92101f452e10680ad4c8af2d5ad40d940b59214.tar.xz
cmd/compile: resolve TODO in inl.go
If the condition is a bool constant, there's no need to walk both branches. Passes toolstash -cmp. Change-Id: I4ee5e3553ce07c2213efba0d33d869b4a1b57783 Reviewed-on: https://go-review.googlesource.com/c/go/+/347911 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/inline')
-rw-r--r--src/cmd/compile/internal/inline/inl.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go
index d50d8b3516..073373144d 100644
--- a/src/cmd/compile/internal/inline/inl.go
+++ b/src/cmd/compile/internal/inline/inl.go
@@ -398,10 +398,14 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
n := n.(*ir.IfStmt)
if ir.IsConst(n.Cond, constant.Bool) {
// This if and the condition cost nothing.
- // TODO(rsc): It seems strange that we visit the dead branch.
- return doList(n.Init(), v.do) ||
- doList(n.Body, v.do) ||
- doList(n.Else, v.do)
+ if doList(n.Init(), v.do) {
+ return true
+ }
+ if ir.BoolVal(n.Cond) {
+ return doList(n.Body, v.do)
+ } else {
+ return doList(n.Else, v.do)
+ }
}
case ir.ONAME: