SmallVector<BasicBlock*, 8> UncondBranchPreds;
SmallVector<BranchInst*, 8> CondBranchPreds;
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
+ if ((*PI)->getUnwindDest() == BB) continue;
+
TerminatorInst *PTI = (*PI)->getTerminator();
if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
if (BI->isUnconditional())
BasicBlock *OnlySucc = 0;
if (OnlyPred && OnlyPred != BB && // Don't break self loops
+ OnlyPred->getUnwindDest() != BB &&
OnlyPred->getTerminator()->getOpcode() != Instruction::Invoke) {
// Check to see if there is only one distinct successor...
succ_iterator SI(succ_begin(OnlyPred)), SE(succ_end(OnlyPred));
}
}
- if (OnlySucc) {
+ if (OnlySucc && (BB->getUnwindDest() == OnlyPred->getUnwindDest() ||
+ !BB->getUnwindDest() || !OnlyPred->getUnwindDest())) {
DOUT << "Merging: " << *BB << "into: " << *OnlyPred;
// Resolve any PHI nodes at the start of the block. They are all
// Move all definitions in the successor to the predecessor.
OnlyPred->getInstList().splice(OnlyPred->end(), BB->getInstList());
+ // Move the unwind_to block
+ if (!OnlyPred->getUnwindDest() && BB->getUnwindDest())
+ OnlyPred->setUnwindDest(BB->getUnwindDest());
+
// Make all PHI nodes that referred to BB now refer to Pred as their
// source.
BB->replaceAllUsesWith(OnlyPred);