summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-07-07 19:51:32 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-07-07 19:51:32 +0000
commit1ce75dcbbcb6a67904a23b4ec701d1e994767c7e (patch)
tree600e0efd70bf6ebe87e37f0f0cfb5d4b7caf5ad9 /lib/Transforms/Scalar
parent85e9212fcdd63d8b796d09c87f99eae5153a6c8a (diff)
downloadllvm-1ce75dcbbcb6a67904a23b4ec701d1e994767c7e.tar.gz
llvm-1ce75dcbbcb6a67904a23b4ec701d1e994767c7e.tar.bz2
llvm-1ce75dcbbcb6a67904a23b4ec701d1e994767c7e.tar.xz
Fix two serious LSR bugs.
1. LSR runOnLoop is always returning false regardless if any transformation is made. 2. AddUsersIfInteresting can create new instructions that are added to DeadInsts. But there is a later early exit which prevents them from being freed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53193 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 7a372024c9..ccb25f05a6 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1737,6 +1737,7 @@ void LoopStrengthReduce::OptimizeIndvars(Loop *L) {
// live ranges for the IV correctly.
CondUse->Offset = SE->getMinusSCEV(CondUse->Offset, *CondStride);
CondUse->isUseOfPostIncrementedValue = true;
+ Changed = true;
}
bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) {
@@ -1754,49 +1755,48 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) {
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I)
AddUsersIfInteresting(I, L, Processed);
- // If we have nothing to do, return.
- if (IVUsesByStride.empty()) return false;
+ if (!IVUsesByStride.empty()) {
+ // Optimize induction variables. Some indvar uses can be transformed to use
+ // strides that will be needed for other purposes. A common example of this
+ // is the exit test for the loop, which can often be rewritten to use the
+ // computation of some other indvar to decide when to terminate the loop.
+ OptimizeIndvars(L);
- // Optimize induction variables. Some indvar uses can be transformed to use
- // strides that will be needed for other purposes. A common example of this
- // is the exit test for the loop, which can often be rewritten to use the
- // computation of some other indvar to decide when to terminate the loop.
- OptimizeIndvars(L);
+ // FIXME: We can widen subreg IV's here for RISC targets. e.g. instead of
+ // doing computation in byte values, promote to 32-bit values if safe.
+ // FIXME: Attempt to reuse values across multiple IV's. In particular, we
+ // could have something like "for(i) { foo(i*8); bar(i*16) }", which should
+ // be codegened as "for (j = 0;; j+=8) { foo(j); bar(j+j); }" on X86/PPC.
+ // Need to be careful that IV's are all the same type. Only works for
+ // intptr_t indvars.
- // FIXME: We can widen subreg IV's here for RISC targets. e.g. instead of
- // doing computation in byte values, promote to 32-bit values if safe.
-
- // FIXME: Attempt to reuse values across multiple IV's. In particular, we
- // could have something like "for(i) { foo(i*8); bar(i*16) }", which should be
- // codegened as "for (j = 0;; j+=8) { foo(j); bar(j+j); }" on X86/PPC. Need
- // to be careful that IV's are all the same type. Only works for intptr_t
- // indvars.
-
- // If we only have one stride, we can more aggressively eliminate some things.
- bool HasOneStride = IVUsesByStride.size() == 1;
+ // If we only have one stride, we can more aggressively eliminate some
+ // things.
+ bool HasOneStride = IVUsesByStride.size() == 1;
#ifndef NDEBUG
- DOUT << "\nLSR on ";
- DEBUG(L->dump());
+ DOUT << "\nLSR on ";
+ DEBUG(L->dump());
#endif
- // IVsByStride keeps IVs for one particular loop.
- assert(IVsByStride.empty() && "Stale entries in IVsByStride?");
-
- // Sort the StrideOrder so we process larger strides first.
- std::stable_sort(StrideOrder.begin(), StrideOrder.end(), StrideCompare());
-
- // Note: this processes each stride/type pair individually. All users passed
- // into StrengthReduceStridedIVUsers have the same type AND stride. Also,
- // note that we iterate over IVUsesByStride indirectly by using StrideOrder.
- // This extra layer of indirection makes the ordering of strides deterministic
- // - not dependent on map order.
- for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e; ++Stride) {
- std::map<SCEVHandle, IVUsersOfOneStride>::iterator SI =
- IVUsesByStride.find(StrideOrder[Stride]);
- assert(SI != IVUsesByStride.end() && "Stride doesn't exist!");
- StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride);
+ // IVsByStride keeps IVs for one particular loop.
+ assert(IVsByStride.empty() && "Stale entries in IVsByStride?");
+
+ // Sort the StrideOrder so we process larger strides first.
+ std::stable_sort(StrideOrder.begin(), StrideOrder.end(), StrideCompare());
+
+ // Note: this processes each stride/type pair individually. All users
+ // passed into StrengthReduceStridedIVUsers have the same type AND stride.
+ // Also, note that we iterate over IVUsesByStride indirectly by using
+ // StrideOrder. This extra layer of indirection makes the ordering of
+ // strides deterministic - not dependent on map order.
+ for (unsigned Stride = 0, e = StrideOrder.size(); Stride != e; ++Stride) {
+ std::map<SCEVHandle, IVUsersOfOneStride>::iterator SI =
+ IVUsesByStride.find(StrideOrder[Stride]);
+ assert(SI != IVUsesByStride.end() && "Stride doesn't exist!");
+ StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride);
+ }
}
// We're done analyzing this loop; release all the state we built up for it.
@@ -1839,5 +1839,5 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) {
DeleteTriviallyDeadInstructions(DeadInsts);
}
- return false;
+ return Changed;
}