Fix bug: test/Regression/Other/2002-03-11-ConstPropCrash.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1858 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-03-11 22:11:07 +00:00
parent 81ba70445f
commit 0fce76a009
3 changed files with 9 additions and 5 deletions

View File

@ -23,9 +23,11 @@ bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &I);
// ConstantFoldTerminator - If a terminator instruction is predicated on a // ConstantFoldTerminator - If a terminator instruction is predicated on a
// constant value, convert it into an unconditional branch to the constant // 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);
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -102,7 +102,8 @@ ConstantFoldBinaryInst(BasicBlock *BB, BasicBlock::iterator &II,
// constant value, convert it into an unconditional branch to the constant // constant value, convert it into an unconditional branch to the constant
// destination. // destination.
// //
bool ConstantFoldTerminator(TerminatorInst *T) { bool ConstantFoldTerminator(BasicBlock *BB, BasicBlock::iterator &II,
TerminatorInst *T) {
// Branch - See if we are conditional jumping on constant // Branch - See if we are conditional jumping on constant
if (BranchInst *BI = dyn_cast<BranchInst>(T)) { if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
if (BI->isUnconditional()) return false; // Can't optimize uncond branch 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 // Set the unconditional destination, and change the insn to be an
// unconditional branch. // unconditional branch.
BI->setUnconditionalDest(Destination); BI->setUnconditionalDest(Destination);
II = BB->end()-1; // Update instruction iterator!
return true; return true;
} }
#if 0 #if 0
@ -171,7 +173,7 @@ bool doConstantPropogation(BasicBlock *BB, BasicBlock::iterator &II) {
Constant *D = dyn_cast<Constant>(UInst->getOperand(0)); Constant *D = dyn_cast<Constant>(UInst->getOperand(0));
if (D) return ConstantFoldUnaryInst(BB, II, UInst, D); if (D) return ConstantFoldUnaryInst(BB, II, UInst, D);
} else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) { } else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) {
return ConstantFoldTerminator(TInst); return ConstantFoldTerminator(BB, II, TInst);
} else if (PHINode *PN = dyn_cast<PHINode>(Inst)) { } else if (PHINode *PN = dyn_cast<PHINode>(Inst)) {
// If it's a PHI node and only has one operand // If it's a PHI node and only has one operand

View File

@ -270,7 +270,7 @@ bool SCCP::doSCCP() {
// Hey, we just changed something! // Hey, we just changed something!
MadeChanges = true; MadeChanges = true;
} else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Inst)) { } else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Inst)) {
MadeChanges |= ConstantFoldTerminator(TI); MadeChanges |= ConstantFoldTerminator(BB, BI, TI);
} }
++BI; ++BI;