Skip to content

Commit 102ab03

Browse files
committed
go/ir: don't emit split stores before phi nodes
Closes: gh-1495
1 parent f57fec2 commit 102ab03

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

go/ir/lift.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,24 @@ func liftable(alloc *Alloc, instructions BlockMap[liftInstructions]) bool {
970970
for i := range blocks {
971971
// Update firstUnliftable to be one after lastLiftable. We do this to include the unliftable's preceding
972972
// DebugRefs in the renaming.
973-
blocks[i].firstUnliftable = blocks[i].lastLiftable + 1
973+
if blocks[i].lastLiftable == -1 && !blocks[i].storeInPreds {
974+
// There are no liftable instructions (for this alloc) in this block. Set firstUnliftable to the
975+
// first non-head instruction to avoid inserting the store before phi instructions, which would
976+
// fail validation.
977+
first := -1
978+
instrLoop:
979+
for i, instr := range fn.Blocks[i].Instrs {
980+
switch instr.(type) {
981+
case *Phi, *Sigma:
982+
default:
983+
first = i
984+
break instrLoop
985+
}
986+
}
987+
blocks[i].firstUnliftable = first
988+
} else {
989+
blocks[i].firstUnliftable = blocks[i].lastLiftable + 1
990+
}
974991
}
975992

976993
// If a block is reachable by a (partially) unliftable block, then the entirety of the block is unliftable. In that

0 commit comments

Comments
 (0)