Skip to content

Commit 1c05b9b

Browse files
randall77heschi
authored andcommitted
[release-branch.go1.17] cmd/compile: fix fuse pass to do CFG surgery correctly
removePred and removeArg do different things. removePred moves the last predecessor to index k, whereas removeArg slides all the args k or greater down by 1 index. Kind of unfortunate different behavior in things named similarly. Fixes golang#49129 Change-Id: I9ae409bdac744e713f4c121f948e43db6fdc8542 Reviewed-on: https://go-review.googlesource.com/c/go/+/358117 Trust: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> (cherry picked from commit 8dbf3e9) Reviewed-on: https://go-review.googlesource.com/c/go/+/358118 Reviewed-by: Austin Clements <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]>
1 parent 364f15f commit 1c05b9b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/cmd/compile/internal/ssa/fuse_branchredirect.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ func fuseBranchRedirect(f *Func) bool {
7878
if v.Op != OpPhi {
7979
continue
8080
}
81-
v.RemoveArg(k)
81+
n := len(v.Args)
82+
v.Args[k].Uses--
83+
v.Args[k] = v.Args[n-1]
84+
v.Args[n-1] = nil
85+
v.Args = v.Args[:n-1]
8286
phielimValue(v)
8387
}
8488
// Fix up child to have one more predecessor.

test/fixedbugs/issue49122.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
var B []bool
10+
var N int
11+
12+
func f(p bool, m map[bool]bool) bool {
13+
var q bool
14+
_ = p || N&N < N || B[0] || B[0]
15+
return p && q && m[q]
16+
}

0 commit comments

Comments
 (0)