mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.ssa] cmd/compile: move tuple selectors to generator's block in CSE
CSE may substitute a tuple generator with another one in a different block. In this case, since we want tuple selectors to stay together with the tuple generator, copy the selector to the new generator's block and rewrite its use. Op.isTupleGenerator and Op.isTupleSelector are introduced to assert tuple ops. Use it in tighten as well. Updates #15365. Change-Id: Ia9e8c734b9cc3bc9fca4a2750041eef9cdfac5a5 Reviewed-on: https://go-review.googlesource.com/24137 Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
8086ce44c4
commit
8eadb89266
3 changed files with 46 additions and 2 deletions
|
|
@ -163,6 +163,29 @@ 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.
|
||||
for _, b := range f.Blocks {
|
||||
for _, v := range b.Values {
|
||||
if rewrite[v.ID] != nil {
|
||||
continue
|
||||
}
|
||||
if !v.Op.isTupleSelector() {
|
||||
continue
|
||||
}
|
||||
if !v.Args[0].Op.isTupleGenerator() {
|
||||
f.Fatalf("arg of tuple selector %s is not a tuple: %s", v.String(), v.Args[0].LongString())
|
||||
}
|
||||
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
|
||||
c := v.copyInto(t.Block)
|
||||
rewrite[v.ID] = c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rewrites := int64(0)
|
||||
|
||||
// Apply substitutions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue