]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove n.SetLikely(false) usage
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 13 Sep 2019 02:58:35 +0000 (09:58 +0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 25 Sep 2019 18:10:51 +0000 (18:10 +0000)
n.SetLikely(false) is probably mean to indicate that the branch is
"unlikely", but it has the real effect of not marking branch as likely.

So invert the test condition, we can use more meaningful n.SetLikely(true).

Before:

if l2 < 0 {
panicmakeslicelen()
}

After:

if l2 >= 0 {
} else {
panicmakeslicelen
}

Fixes #32486

Change-Id: I156fdba1f9a5d554a178c8903f1a391ed304199d
Reviewed-on: https://go-review.googlesource.com/c/go/+/195197
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/walk.go

index 4c89ae639babbe5d0bfec7b7d9f87eccd8bc74ef..ceec1b4dc1e1dac0562290ff5b4f204643af5d2e 100644 (file)
@@ -2711,7 +2711,8 @@ func isAppendOfMake(n *Node) bool {
 
 // extendslice rewrites append(l1, make([]T, l2)...) to
 //   init {
-//     if l2 < 0 {
+//     if l2 >= 0 { // Empty if block here for more meaningful node.SetLikely(true)
+//     } else {
 //       panicmakeslicelen()
 //     }
 //     s := l1
@@ -2750,12 +2751,12 @@ func extendslice(n *Node, init *Nodes) *Node {
 
        var nodes []*Node
 
-       // if l2 < 0
-       nifneg := nod(OIF, nod(OLT, l2, nodintconst(0)), nil)
-       nifneg.SetLikely(false)
+       // if l2 >= 0 (likely happens), do nothing
+       nifneg := nod(OIF, nod(OGE, l2, nodintconst(0)), nil)
+       nifneg.SetLikely(true)
 
-       // panicmakeslicelen()
-       nifneg.Nbody.Set1(mkcall("panicmakeslicelen", nil, init))
+       // else panicmakeslicelen()
+       nifneg.Rlist.Set1(mkcall("panicmakeslicelen", nil, init))
        nodes = append(nodes, nifneg)
 
        // s := l1