1
0
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:
Alan Donovan 2014-04-24 09:08:21 -04:00
parent 35875c1a92
commit 7d1d69032b
2 changed files with 14 additions and 0 deletions

View File

@ -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 {

View File

@ -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
}