diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 15ea761f2ce..ad78506ad42 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1236,6 +1236,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { } else if (SwitchInst *SI = dyn_cast(TI)) { for (unsigned i = 1, e = SI->getNumCases(); i != e; ++i) if (SI->getSuccessor(i) == BB) { + BB->removePredecessor(SI->getParent()); SI->removeCase(i); --i; --e; Changed = true; @@ -1263,6 +1264,12 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { SI->setSuccessor(0, MaxBlock); Changed = true; + // If MaxBlock has phinodes in it, remove MaxPop-1 entries from + // it. + if (isa(MaxBlock->begin())) + for (unsigned i = 0; i != MaxPop-1; ++i) + MaxBlock->removePredecessor(SI->getParent()); + for (unsigned i = 1, e = SI->getNumCases(); i != e; ++i) if (SI->getSuccessor(i) == MaxBlock) { SI->removeCase(i);