// if we rewrite a tuple generator to a new one in a different block,
// copy its selectors to the new generator's block, so tuple generator
// and selectors stay together.
+ // be careful not to copy same selectors more than once (issue 16741).
+ copiedSelects := make(map[ID][]*Value)
for _, b := range f.Blocks {
+ out:
for _, v := range b.Values {
if rewrite[v.ID] != nil {
continue
t := rewrite[v.Args[0].ID]
if t != nil && t.Block != b {
// v.Args[0] is tuple generator, CSE'd into a different block as t, v is left behind
+ for _, c := range copiedSelects[t.ID] {
+ if v.Op == c.Op {
+ // an equivalent selector is already copied
+ rewrite[v.ID] = c
+ continue out
+ }
+ }
c := v.copyInto(t.Block)
rewrite[v.ID] = c
+ copiedSelects[t.ID] = append(copiedSelects[t.ID], c)
}
}
}
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// Make sure CSE of multi-output opcodes works correctly
+// with select0/1 operations.
+
+package main
+
+func div(d, r int64) int64 {
+ if m := d % r; m > 0 {
+ return d/r + 1
+ }
+ return d / r
+}