Improve handling of unreachable blocks in mem2reg.

We were handling regular uses, but not handling promotions in things
like debug_value_addr.

This was exposed by some pass ordering changes I have in an upcoming
commit.
This commit is contained in:
Mark Lacey
2016-02-22 11:35:44 -08:00
parent 9b4f24ef71
commit bc36b2a601
2 changed files with 24 additions and 8 deletions

View File

@@ -568,7 +568,8 @@ StackAllocationPromoter::getLiveInValue(BlockSet &PhiBlocks,
return BB->getBBArg(BB->getNumBBArg()-1);
}
assert(DT->getNode(BB) && "Block is not in dominator tree!");
if (BB->pred_empty() || !DT->getNode(BB))
return SILUndef::get(ASI->getElementType(), ASI->getModule());
// No phi for this value in this block means that the value flowing
// out of the immediate dominator reaches here.
@@ -610,14 +611,10 @@ void StackAllocationPromoter::fixBranchesAndUses(BlockSet &PhiBlocks) {
// examining is a value, replace it with undef. Either way, delete
// the instruction and move on.
SILBasicBlock *BB = LI->getParent();
if (BB->pred_empty() || !DT->getNode(BB)) {
Def = SILUndef::get(ASI->getElementType(), ASI->getModule());
} else {
Def = getLiveInValue(PhiBlocks, BB);
}
Def = getLiveInValue(PhiBlocks, BB);
DEBUG(llvm::dbgs() << "*** Replacing " << *LI << " with Def " << *Def);
// Replace the load with the definition that we found.
replaceLoad(LI, Def, ASI);
removedUser = true;