diff options
| author | Chris Lattner <sabre@nondot.org> | 2002-03-11 22:11:07 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2002-03-11 22:11:07 +0000 |
| commit | 477fe0845af9914f3adaee7dd76377d598628cf5 (patch) | |
| tree | 76fe72b8f2520fe7fff2d9bba13ba7a46be9263f | |
| parent | 7d1c5b31b6ea46c985dd422870f0fea3811a259b (diff) | |
| download | bcm5719-llvm-477fe0845af9914f3adaee7dd76377d598628cf5.tar.gz bcm5719-llvm-477fe0845af9914f3adaee7dd76377d598628cf5.zip | |
Fix bug: test/Regression/Other/2002-03-11-ConstPropCrash.ll
llvm-svn: 1858
| -rw-r--r-- | llvm/include/llvm/Transforms/Scalar/ConstantProp.h | 6 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/ConstantProp.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 2 |
3 files changed, 9 insertions, 5 deletions
diff --git a/llvm/include/llvm/Transforms/Scalar/ConstantProp.h b/llvm/include/llvm/Transforms/Scalar/ConstantProp.h index 3a8fa5b6d9a..0da13e9fdbd 100644 --- a/llvm/include/llvm/Transforms/Scalar/ConstantProp.h +++ b/llvm/include/llvm/Transforms/Scalar/ConstantProp.h @@ -23,9 +23,11 @@ bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &I); // ConstantFoldTerminator - If a terminator instruction is predicated on a // constant value, convert it into an unconditional branch to the constant -// destination. +// destination. This is a nontrivial operation because the successors of this +// basic block must have their PHI nodes updated. // -bool ConstantFoldTerminator(TerminatorInst *T); +bool ConstantFoldTerminator(BasicBlock *BB, BasicBlock::iterator &I, + TerminatorInst *T); //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Transforms/Scalar/ConstantProp.cpp b/llvm/lib/Transforms/Scalar/ConstantProp.cpp index fc4e3bf0e3e..624e6da39da 100644 --- a/llvm/lib/Transforms/Scalar/ConstantProp.cpp +++ b/llvm/lib/Transforms/Scalar/ConstantProp.cpp @@ -102,7 +102,8 @@ ConstantFoldBinaryInst(BasicBlock *BB, BasicBlock::iterator &II, // constant value, convert it into an unconditional branch to the constant // destination. // -bool ConstantFoldTerminator(TerminatorInst *T) { +bool ConstantFoldTerminator(BasicBlock *BB, BasicBlock::iterator &II, + TerminatorInst *T) { // Branch - See if we are conditional jumping on constant if (BranchInst *BI = dyn_cast<BranchInst>(T)) { if (BI->isUnconditional()) return false; // Can't optimize uncond branch @@ -127,6 +128,7 @@ bool ConstantFoldTerminator(TerminatorInst *T) { // Set the unconditional destination, and change the insn to be an // unconditional branch. BI->setUnconditionalDest(Destination); + II = BB->end()-1; // Update instruction iterator! return true; } #if 0 @@ -171,7 +173,7 @@ bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &II) { Constant *D = dyn_cast<Constant>(UInst->getOperand(0)); if (D) return ConstantFoldUnaryInst(BB, II, UInst, D); } else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) { - return ConstantFoldTerminator(TInst); + return ConstantFoldTerminator(BB, II, TInst); } else if (PHINode *PN = dyn_cast<PHINode>(Inst)) { // If it's a PHI node and only has one operand diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 447a3e19600..2bf6c86e95a 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -270,7 +270,7 @@ bool SCCP::doSCCP() { // Hey, we just changed something! MadeChanges = true; } else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Inst)) { - MadeChanges |= ConstantFoldTerminator(TI); + MadeChanges |= ConstantFoldTerminator(BB, BI, TI); } ++BI; |

