]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix fuse pass to do CFG surgery correctly
authorKeith Randall <khr@golang.org>
Sat, 23 Oct 2021 17:16:41 +0000 (10:16 -0700)
committerKeith Randall <khr@golang.org>
Sat, 23 Oct 2021 20:23:35 +0000 (20:23 +0000)
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 #49122

Change-Id: I9ae409bdac744e713f4c121f948e43db6fdc8542
Reviewed-on: https://go-review.googlesource.com/c/go/+/358117
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ssa/fuse_branchredirect.go
test/fixedbugs/issue49122.go [new file with mode: 0644]

index 1b8b307bcac7a213880b25ca64f71eff41639dc7..ba5220bd87ca2ee64b4befc8da437c093076491d 100644 (file)
@@ -78,7 +78,11 @@ func fuseBranchRedirect(f *Func) bool {
                                        if v.Op != OpPhi {
                                                continue
                                        }
-                                       v.RemoveArg(k)
+                                       n := len(v.Args)
+                                       v.Args[k].Uses--
+                                       v.Args[k] = v.Args[n-1]
+                                       v.Args[n-1] = nil
+                                       v.Args = v.Args[:n-1]
                                        phielimValue(v)
                                }
                                // Fix up child to have one more predecessor.
diff --git a/test/fixedbugs/issue49122.go b/test/fixedbugs/issue49122.go
new file mode 100644 (file)
index 0000000..c62a627
--- /dev/null
@@ -0,0 +1,16 @@
+// compile
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var B []bool
+var N int
+
+func f(p bool, m map[bool]bool) bool {
+       var q bool
+       _ = p || N&N < N || B[0] || B[0]
+       return p && q && m[q]
+}