From dc42f48ea90132509e678028e7dbab5544ef0794 Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Tue, 20 Mar 2007 00:47:50 +0000 Subject: [PATCH] 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 --- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 35 ++++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index c40084cc8ff..bd74902c53c 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& UsersToProcess); + + bool ValidStride(int64_t, const std::vector& 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& 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& UsersToProcess) { if (!TLI) return 0; if (SCEVConstant *SC = dyn_cast(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::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";