mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
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: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
2b8e143dc3
commit
3d5cf72ca9
|
@ -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) {
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
test/fixedbugs/issue16741.go
Normal file
17
test/fixedbugs/issue16741.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// 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
|
||||||
|
}
|
Loading…
Reference in a new issue