mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +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
2 changed files with 28 additions and 0 deletions
|
|
@ -166,7 +166,10 @@ func cse(f *Func) {
|
|||
// 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
|
||||
|
|
@ -180,8 +183,16 @@ func cse(f *Func) {
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue