if (Value *PNV = PN->hasConstantValue()) {
if (Instruction *U = dyn_cast<Instruction>(PNV))
Insts.insert(U);
- PN->replaceAllUsesWith(PNV);
SE->deleteValueFromRecords(PN);
+ PN->replaceAllUsesWith(PNV);
PN->eraseFromParent();
Changed = true;
continue;
// Remove the old compare instruction. The old indvar is probably dead too.
DeadInsts.insert(cast<Instruction>(CondUse->OperandValToReplace));
- OldCond->replaceAllUsesWith(Cond);
SE->deleteValueFromRecords(OldCond);
+ OldCond->replaceAllUsesWith(Cond);
OldCond->eraseFromParent();
IVUsesByStride[*CondStride].Users.pop_back();
#endif
// IVsByStride keeps IVs for one particular loop.
- IVsByStride.clear();
+ assert(IVsByStride.empty() && "Stale entries in IVsByStride?");
// Sort the StrideOrder so we process larger strides first.
std::stable_sort(StrideOrder.begin(), StrideOrder.end(), StrideCompare());
StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride);
}
+ // We're done analyzing this loop; release all the state we built up for it.
+ CastedPointers.clear();
+ IVUsesByStride.clear();
+ IVsByStride.clear();
+ StrideOrder.clear();
+
// Clean up after ourselves
if (!DeadInsts.empty()) {
DeleteTriviallyDeadInstructions(DeadInsts);
if (BO->hasOneUse() && PN == *(BO->use_begin())) {
DeadInsts.insert(BO);
// Break the cycle, then delete the PHI.
- PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
SE->deleteValueFromRecords(PN);
+ PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
PN->eraseFromParent();
}
}
DeleteTriviallyDeadInstructions(DeadInsts);
}
- CastedPointers.clear();
- IVUsesByStride.clear();
- StrideOrder.clear();
return false;
}