1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

More IndVarSimplify cleanup.

llvm-svn: 153362
This commit is contained in:
Andrew Trick 2012-03-24 00:51:17 +00:00
parent 277fa2bfe2
commit 0ff69472e6

View File

@ -1672,34 +1672,25 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
// Eliminate redundant IV cycles. // Eliminate redundant IV cycles.
NumElimIV += Rewriter.replaceCongruentIVs(L, DT, DeadInsts); NumElimIV += Rewriter.replaceCongruentIVs(L, DT, DeadInsts);
// Compute the type of the largest recurrence expression, and decide whether
// a canonical induction variable should be inserted.
bool ExpandBECount = canExpandBackedgeTakenCount(L, SE);
// Now that we know the largest of the induction variable expressions
// in this loop, insert a canonical induction variable of the largest size.
PHINode *IndVar = 0;
if (ExpandBECount && needsLFTR(L, DT)) {
IndVar = FindLoopCounter(L, BackedgeTakenCount, SE, DT, TD);
}
// If we have a trip count expression, rewrite the loop's exit condition // If we have a trip count expression, rewrite the loop's exit condition
// using it. We can currently only handle loops with a single exit. // using it. We can currently only handle loops with a single exit.
Value *NewICmp = 0; if (canExpandBackedgeTakenCount(L, SE) && needsLFTR(L, DT)) {
if (ExpandBECount && IndVar) { PHINode *IndVar = FindLoopCounter(L, BackedgeTakenCount, SE, DT, TD);
// Check preconditions for proper SCEVExpander operation. SCEV does not if (IndVar) {
// express SCEVExpander's dependencies, such as LoopSimplify. Instead any // Check preconditions for proper SCEVExpander operation. SCEV does not
// pass that uses the SCEVExpander must do it. This does not work well for // express SCEVExpander's dependencies, such as LoopSimplify. Instead any
// loop passes because SCEVExpander makes assumptions about all loops, while // pass that uses the SCEVExpander must do it. This does not work well for
// LoopPassManager only forces the current loop to be simplified. // loop passes because SCEVExpander makes assumptions about all loops, while
// // LoopPassManager only forces the current loop to be simplified.
// FIXME: SCEV expansion has no way to bail out, so the caller must //
// explicitly check any assumptions made by SCEV. Brittle. // FIXME: SCEV expansion has no way to bail out, so the caller must
const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(BackedgeTakenCount); // explicitly check any assumptions made by SCEV. Brittle.
if (!AR || AR->getLoop()->getLoopPreheader()) const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(BackedgeTakenCount);
NewICmp = if (!AR || AR->getLoop()->getLoopPreheader())
LinearFunctionTestReplace(L, BackedgeTakenCount, IndVar, Rewriter); (void)LinearFunctionTestReplace(L, BackedgeTakenCount, IndVar,
Rewriter);
}
} }
// Clear the rewriter cache, because values that are in the rewriter's cache // Clear the rewriter cache, because values that are in the rewriter's cache
// can be deleted in the loop below, causing the AssertingVH in the cache to // can be deleted in the loop below, causing the AssertingVH in the cache to
// trigger. // trigger.