mirror of
https://github.com/golang/go
synced 2024-11-18 18:04:46 -07:00
go.tools/go/ssa: don't attempt fusion on single-pred blocks with φ-nodes
During block optimization, degenerate conditional logic such as "false && x" may result in single-predecessor blocks containing φ-nodes. (Ideally such φ-nodes would be replaced by their sole operand, but that requires Referrers information which isn't computed until later.) It is obviously not safe to fuse such blocks, so now we don't. Fixes golang/go#7840 LGTM=gri R=gri CC=golang-codereviews, pcc https://golang.org/cl/90620043
This commit is contained in:
parent
35875c1a92
commit
7d1d69032b
@ -117,6 +117,14 @@ func fuseBlocks(f *Function, a *BasicBlock) bool {
|
||||
if len(b.Preds) != 1 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Degenerate &&/|| ops may result in a straight-line CFG
|
||||
// containing φ-nodes. (Ideally we'd replace such them with
|
||||
// their sole operand but that requires Referrers, built later.)
|
||||
if b.hasPhi() {
|
||||
return false // not sound without further effort
|
||||
}
|
||||
|
||||
// Eliminate jump at end of A, then copy all of B across.
|
||||
a.Instrs = append(a.Instrs[:len(a.Instrs)-1], b.Instrs...)
|
||||
for _, instr := range b.Instrs {
|
||||
|
6
go/ssa/interp/testdata/coverage.go
vendored
6
go/ssa/interp/testdata/coverage.go
vendored
@ -636,3 +636,9 @@ func init() {
|
||||
panic(got)
|
||||
}
|
||||
}
|
||||
|
||||
// Regression test for issue 7840 (covered by SSA sanity checker).
|
||||
func bug7840() bool {
|
||||
// This creates a single-predecessor block with a φ-node.
|
||||
return false && a == 0 && a == 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user