diff options
author | Dale Johannesen <dalej@apple.com> | 2007-03-20 21:54:54 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-03-20 21:54:54 +0000 |
commit | 8e59e163db8cd3e7b4c96e438fbedf78bff06707 (patch) | |
tree | 00cc4ff26c89511c0db563a4c9e9742b4ff74b1e /lib/Transforms/Scalar/LoopStrengthReduce.cpp | |
parent | 69cb9b78f11d505f4351a269fc90e7b77fcda437 (diff) |
do not share old induction variables when this would result in invalid
instructions (that would have to be split later)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35227 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopStrengthReduce.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 4353134093..4ace17f7a4 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -883,9 +883,16 @@ static bool isZero(SCEVHandle &V) { /// 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())) + int64_t Imm; + for (unsigned i=0, e = UsersToProcess.size(); i!=e; ++i) { + if (SCEVConstant *SC = dyn_cast<SCEVConstant>(UsersToProcess[i].Imm)) + Imm = SC->getValue()->getSExtValue(); + else + Imm = 0; + if (!TLI->isLegalAddressScaleAndImm(Scale, Imm, + UsersToProcess[i].Inst->getType())) return false; + } return true; } @@ -968,22 +975,6 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride, SCEVHandle CommonExprs = RemoveCommonExpressionsFromUseBases(UsersToProcess); - // Check if it is possible to reuse a IV with stride that is factor of this - // stride. And the multiple is a number that can be encoded in the scale - // field of the target addressing mode. - PHINode *NewPHI = NULL; - Value *IncV = NULL; - IVExpr ReuseIV; - unsigned RewriteFactor = CheckForIVReuse(Stride, ReuseIV, - CommonExprs->getType(), - UsersToProcess); - if (RewriteFactor != 0) { - DOUT << "BASED ON IV of STRIDE " << *ReuseIV.Stride - << " and BASE " << *ReuseIV.Base << " :\n"; - NewPHI = ReuseIV.PHI; - IncV = ReuseIV.IncV; - } - // Next, figure out what we can represent in the immediate fields of // instructions. If we can represent anything there, move it to the imm // fields of the BasedUsers. We do this so that it increases the commonality @@ -1011,6 +1002,23 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride, } } + // Check if it is possible to reuse a IV with stride that is factor of this + // stride. And the multiple is a number that can be encoded in the scale + // field of the target addressing mode. And we will have a valid + // instruction after this substition, including the immediate field, if any. + PHINode *NewPHI = NULL; + Value *IncV = NULL; + IVExpr ReuseIV; + unsigned RewriteFactor = CheckForIVReuse(Stride, ReuseIV, + CommonExprs->getType(), + UsersToProcess); + if (RewriteFactor != 0) { + DOUT << "BASED ON IV of STRIDE " << *ReuseIV.Stride + << " and BASE " << *ReuseIV.Base << " :\n"; + NewPHI = ReuseIV.PHI; + IncV = ReuseIV.IncV; + } + // Now that we know what we need to do, insert the PHI node itself. // DOUT << "INSERTING IV of STRIDE " << *Stride << " and BASE " |