diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-23 18:57:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-23 18:57:02 +0000 |
commit | ddaaa374879f2f736f7bfa20f4b25202fcb85708 (patch) | |
tree | 4b94e5c9a7cead345ca2622ba5f61a7bf0e34088 /lib/Transforms | |
parent | e285d59ee644ec8730209a5b843352ce7d9eb2eb (diff) |
Handle fallout from the recent branch-on-undef changes. This fixes
Prolangs-C/agrep and SCCP/2006-10-23-IPSCCP-Crash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31132 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index a55e4812df..44634cd7c3 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1360,7 +1360,30 @@ bool IPSCCP::runOnModule(Module &M) { while (!DeadBB->use_empty()) { Instruction *I = cast<Instruction>(DeadBB->use_back()); bool Folded = ConstantFoldTerminator(I->getParent()); - assert(Folded && "Didn't fold away reference to block!"); + if (!Folded) { + // The constant folder may not have been able to fold the termiantor + // if this is a branch or switch on undef. Fold it manually as a + // branch to the first successor. + if (BranchInst *BI = dyn_cast<BranchInst>(I)) { + assert(BI->isConditional() && isa<UndefValue>(BI->getCondition()) && + "Branch should be foldable!"); + } else if (SwitchInst *SI = dyn_cast<SwitchInst>(I)) { + assert(isa<UndefValue>(SI->getCondition()) && "Switch should fold"); + } else { + assert(0 && "Didn't fold away reference to block!"); + } + + // Make this an uncond branch to the first successor. + TerminatorInst *TI = I->getParent()->getTerminator(); + new BranchInst(TI->getSuccessor(0), TI); + + // Remove entries in successor phi nodes to remove edges. + for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i) + TI->getSuccessor(i)->removePredecessor(TI->getParent()); + + // Remove the old terminator. + TI->eraseFromParent(); + } } // Finally, delete the basic block. |