else
Opcode = ICmpInst::ICMP_EQ;
- DEBUG(errs() << "INDVARS: Rewriting loop exit condition to:\n"
+ DEBUG(dbgs() << "INDVARS: Rewriting loop exit condition to:\n"
<< " LHS:" << *CmpIndVar << '\n'
<< " op:\t"
<< (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n"
// Check that InVal is defined in the loop.
Instruction *Inst = cast<Instruction>(InVal);
- if (!L->contains(Inst->getParent()))
+ if (!L->contains(Inst))
continue;
// Okay, this instruction has a user outside of the current loop
Value *ExitVal = Rewriter.expandCodeFor(ExitValue, PN->getType(), Inst);
- DEBUG(errs() << "INDVARS: RLEV: AfterLoopVal = " << *ExitVal << '\n'
+ DEBUG(dbgs() << "INDVARS: RLEV: AfterLoopVal = " << *ExitVal << '\n'
<< " LoopVal = " << *Inst << "\n");
PN->setIncomingValue(i, ExitVal);
if (NumPreds != 1) {
// Clone the PHI and delete the original one. This lets IVUsers and
// any other maps purge the original user from their records.
- PHINode *NewPN = PN->clone(PN->getContext());
+ PHINode *NewPN = cast<PHINode>(PN->clone());
NewPN->takeName(PN);
NewPN->insertBefore(PN);
PN->replaceAllUsesWith(NewPN);
// may not have been able to compute a trip count. Now that we've done some
// re-writing, the trip count may be computable.
if (Changed)
- SE->forgetLoopBackedgeTakenCount(L);
+ SE->forgetLoop(L);
}
bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
++NumInserted;
Changed = true;
- DEBUG(errs() << "INDVARS: New CanIV: " << *IndVar << '\n');
+ DEBUG(dbgs() << "INDVARS: New CanIV: " << *IndVar << '\n');
// Now that the official induction variable is established, reinsert
// the old canonical-looking variable after it so that the IR remains
IU->AddUsersIfInteresting(cast<Instruction>(NewICmp->getOperand(0)));
// Clean up dead instructions.
- DeleteDeadPHIs(L->getHeader());
+ Changed |= DeleteDeadPHIs(L->getHeader());
// Check a post-condition.
assert(L->isLCSSAForm() && "Indvars did not leave the loop in lcssa form!");
return Changed;
NewVal->takeName(Op);
User->replaceUsesOfWith(Op, NewVal);
UI->setOperandValToReplace(NewVal);
- DEBUG(errs() << "INDVARS: Rewrote IV '" << *AR << "' " << *Op << '\n'
+ DEBUG(dbgs() << "INDVARS: Rewrote IV '" << *AR << "' " << *Op << '\n'
<< " into = " << *NewVal << "\n");
++NumRemoved;
Changed = true;
BasicBlock *ExitBlock = L->getExitBlock();
if (!ExitBlock) return;
- Instruction *InsertPt = ExitBlock->getFirstNonPHI();
BasicBlock *Preheader = L->getLoopPreheader();
+ if (!Preheader) return;
+
+ Instruction *InsertPt = ExitBlock->getFirstNonPHI();
BasicBlock::iterator I = Preheader->getTerminator();
while (I != Preheader->begin()) {
--I;