diff options
author | Dale Johannesen <dalej@apple.com> | 2007-03-20 00:47:50 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-03-20 00:47:50 +0000 |
commit | dc42f48ea90132509e678028e7dbab5544ef0794 (patch) | |
tree | 70289c4e5aa60ac01373b9aa4bf6813f699edb6d /lib/Transforms/Scalar/LoopStrengthReduce.cpp | |
parent | 80dae195c75a3ef38854645ae3cf41f8ae835644 (diff) | |
download | llvm-dc42f48ea90132509e678028e7dbab5544ef0794.tar.gz llvm-dc42f48ea90132509e678028e7dbab5544ef0794.tar.bz2 llvm-dc42f48ea90132509e678028e7dbab5544ef0794.tar.xz |
use types of loads and stores, not address, in CheckForIVReuse
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35197 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopStrengthReduce.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index c40084cc8f..bd74902c53 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -43,6 +43,9 @@ STATISTIC(NumInserted, "Number of PHIs inserted"); STATISTIC(NumVariable, "Number of PHIs with variable strides"); namespace { + + class BasedUser; + /// IVStrideUse - Keep track of one use of a strided induction variable, where /// the stride is stored externally. The Offset member keeps track of the /// offset from the IV, User is the actual user of the operand, and 'Operand' @@ -174,7 +177,10 @@ private: void OptimizeIndvars(Loop *L); - unsigned CheckForIVReuse(const SCEVHandle&, IVExpr&, const Type*); + unsigned CheckForIVReuse(const SCEVHandle&, IVExpr&, const Type*, + const std::vector<BasedUser>& UsersToProcess); + + bool ValidStride(int64_t, const std::vector<BasedUser>& UsersToProcess); void StrengthReduceStridedIVUsers(const SCEVHandle &Stride, IVUsersOfOneStride &Uses, @@ -871,13 +877,25 @@ static bool isZero(SCEVHandle &V) { return false; } +/// ValidStride - Check whether the given Scale is valid for all loads and +/// stores in UsersToProcess. Pulled into a function to avoid disturbing the +/// sensibilities of those who dislike goto's. +/// +bool LoopStrengthReduce::ValidStride(int64_t Scale, + const std::vector<BasedUser>& UsersToProcess) { + for (unsigned i=0, e = UsersToProcess.size(); i!=e; ++i) + if (!TLI->isLegalAddressScale(Scale, UsersToProcess[i].Inst->getType())) + return false; + return true; +} /// CheckForIVReuse - Returns the multiple if the stride is the multiple /// of a previous stride and it is a legal value for the target addressing /// mode scale component. This allows the users of this stride to be rewritten /// as prev iv * factor. It returns 0 if no reuse is possible. -unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride, - IVExpr &IV, const Type *Ty) { +unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride, + IVExpr &IV, const Type *Ty, + const std::vector<BasedUser>& UsersToProcess) { if (!TLI) return 0; if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) { @@ -890,7 +908,11 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride, if (unsigned(abs(SInt)) < SSInt || (SInt % SSInt) != 0) continue; int64_t Scale = SInt / SSInt; - if (TLI->isLegalAddressScale(Scale, Ty)) { + // Check that this stride is valid for all the types used for loads and + // stores; if it can be used for some and not others, we might as well use + // the original stride everywhere, since we have to create the IV for it + // anyway. + if (ValidStride(Scale, UsersToProcess)) for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(), IE = SI->second.IVs.end(); II != IE; ++II) // FIXME: Only handle base == 0 for now. @@ -899,10 +921,8 @@ unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride, IV = *II; return Scale; } - } } } - return 0; } @@ -955,7 +975,8 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride, Value *IncV = NULL; IVExpr ReuseIV; unsigned RewriteFactor = CheckForIVReuse(Stride, ReuseIV, - CommonExprs->getType()); + CommonExprs->getType(), + UsersToProcess); if (RewriteFactor != 0) { DOUT << "BASED ON IV of STRIDE " << *ReuseIV.Stride << " and BASE " << *ReuseIV.Base << " :\n"; |