Commit 3d5cf72c authored by Cherry Zhang's avatar Cherry Zhang

cmd/compile: CSE copied tuple selectors

In CSE if a tuple generator is CSE'd to a different block, its
selectors are copied to the same block. In this case, also CES
the copied selectors.

Test copied from Keith's CL 27202.

Fixes #16741.

Change-Id: I2fc8b9513d430f10d6104275cfff5fb75d3ef3d9
Reviewed-on: https://go-review.googlesource.com/27236
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarDavid Chase <drchase@google.com>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
parent 2b8e143d
...@@ -166,7 +166,10 @@ func cse(f *Func) { ...@@ -166,7 +166,10 @@ func cse(f *Func) {
// if we rewrite a tuple generator to a new one in a different block, // 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 // copy its selectors to the new generator's block, so tuple generator
// and selectors stay together. // 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 { for _, b := range f.Blocks {
out:
for _, v := range b.Values { for _, v := range b.Values {
if rewrite[v.ID] != nil { if rewrite[v.ID] != nil {
continue continue
...@@ -180,8 +183,16 @@ func cse(f *Func) { ...@@ -180,8 +183,16 @@ func cse(f *Func) {
t := rewrite[v.Args[0].ID] t := rewrite[v.Args[0].ID]
if t != nil && t.Block != b { if t != nil && t.Block != b {
// v.Args[0] is tuple generator, CSE'd into a different block as t, v is left behind // 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) c := v.copyInto(t.Block)
rewrite[v.ID] = c rewrite[v.ID] = c
copiedSelects[t.ID] = append(copiedSelects[t.ID], c)
} }
} }
} }
......
// 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment