Fix simplifycfg crash in handing block merge.

llvm-svn: 55971
This commit is contained in:
Devang Patel
2008-09-09 01:06:56 +00:00
parent 41cf9dedc6
commit 0f7a3507cf
2 changed files with 71 additions and 1 deletions

View File

@@ -54,7 +54,17 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) {
// Can't merge if there are multiple successors.
if (!OnlySucc) return false;
// Can't merge if there is PHI loop.
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; ++BI) {
if (PHINode *PN = dyn_cast<PHINode>(BI)) {
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (PN->getIncomingValue(i) == PN)
return false;
} else
break;
}
// Begin by getting rid of unneeded PHIs.
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
PN->replaceAllUsesWith(PN->getIncomingValue(0));