Changes in directory llvm/lib/Transforms/Scalar:
LoopStrengthReduce.cpp updated: 1.85 -> 1.86 --- Log message: Only reuse a previous IV if it would not require a type conversion. --- Diffs of the changes: (+17 -14) LoopStrengthReduce.cpp | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.85 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.86 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.85 Wed Jun 28 18:17:24 2006 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Tue Jul 18 14:07:58 2006 @@ -187,7 +187,7 @@ void OptimizeIndvars(Loop *L); - unsigned CheckForIVReuse(const SCEVHandle &Stride, IVExpr &IV); + unsigned CheckForIVReuse(const SCEVHandle&, IVExpr&, const Type*); void StrengthReduceStridedIVUsers(const SCEVHandle &Stride, IVUsersOfOneStride &Uses, @@ -872,7 +872,7 @@ /// 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) { + IVExpr &IV, const Type *Ty) { if (!TLI) return 0; if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) { @@ -892,7 +892,9 @@ 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. - if (isZero(II->Base)) { + // Only reuse previous IV if it would not require a type conversion. + if (isZero(II->Base) && + II->Base->getType()->isLosslesslyConvertibleTo(Ty)) { IV = *II; return Scale; } @@ -929,13 +931,24 @@ "Base value is not loop invariant!"); } + // We now have a whole bunch of uses of like-strided induction variables, but + // they might all have different bases. We want to emit one PHI node for this + // stride which we fold as many common expressions (between the IVs) into as + // possible. Start by identifying the common expressions in the base values + // for the strides (e.g. if we have "A+C+B" and "A+B+D" as our bases, find + // "A+B"), emit it to the preheader, then remove the expression from the + // UsersToProcess base values. + 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); + unsigned RewriteFactor = CheckForIVReuse(Stride, ReuseIV, + CommonExprs->getType()); if (RewriteFactor != 0) { DEBUG(std::cerr << "BASED ON IV of STRIDE " << *ReuseIV.Stride << " and BASE " << *ReuseIV.Base << " :\n"); @@ -943,16 +956,6 @@ IncV = ReuseIV.IncV; } - // We now have a whole bunch of uses of like-strided induction variables, but - // they might all have different bases. We want to emit one PHI node for this - // stride which we fold as many common expressions (between the IVs) into as - // possible. Start by identifying the common expressions in the base values - // for the strides (e.g. if we have "A+C+B" and "A+B+D" as our bases, find - // "A+B"), emit it to the preheader, then remove the expression from the - // UsersToProcess base values. - SCEVHandle CommonExprs = - RemoveCommonExpressionsFromUseBases(UsersToProcess); - // 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 _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits