diff --git a/llvm/include/llvm/Analysis/DependenceAnalysis.h b/llvm/include/llvm/Analysis/DependenceAnalysis.h --- a/llvm/include/llvm/Analysis/DependenceAnalysis.h +++ b/llvm/include/llvm/Analysis/DependenceAnalysis.h @@ -926,6 +926,12 @@ bool tryDelinearize(Instruction *Src, Instruction *Dst, SmallVectorImpl &Pair); + + private: + /// checkSubscript - Helper function for checkSrcSubscript and + /// checkDstSubscript to avoid duplicate code + bool checkSubscript(const SCEV *Expr, const Loop *LoopNest, + SmallBitVector &Loops, bool IsSrc); }; // class DependenceInfo /// AnalysisPass to compute dependence information in a function diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp --- a/llvm/lib/Analysis/DependenceAnalysis.cpp +++ b/llvm/lib/Analysis/DependenceAnalysis.cpp @@ -882,14 +882,13 @@ } } - // Examine the scev and return true iff it's linear. // Collect any loops mentioned in the set of "Loops". -bool DependenceInfo::checkSrcSubscript(const SCEV *Src, const Loop *LoopNest, - SmallBitVector &Loops) { - const SCEVAddRecExpr *AddRec = dyn_cast(Src); +bool DependenceInfo::checkSubscript(const SCEV *Expr, const Loop *LoopNest, + SmallBitVector &Loops, bool IsSrc) { + const SCEVAddRecExpr *AddRec = dyn_cast(Expr); if (!AddRec) - return isLoopInvariant(Src, LoopNest); + return isLoopInvariant(Expr, LoopNest); const SCEV *Start = AddRec->getStart(); const SCEV *Step = AddRec->getStepRecurrence(*SE); const SCEV *UB = SE->getBackedgeTakenCount(AddRec->getLoop()); @@ -902,33 +901,25 @@ } if (!isLoopInvariant(Step, LoopNest)) return false; - Loops.set(mapSrcLoop(AddRec->getLoop())); - return checkSrcSubscript(Start, LoopNest, Loops); + if (IsSrc) + Loops.set(mapSrcLoop(AddRec->getLoop())); + else + Loops.set(mapDstLoop(AddRec->getLoop())); + return checkSubscript(Start, LoopNest, Loops, IsSrc); } - +// Examine the scev and return true iff it's linear. +// Collect any loops mentioned in the set of "Loops". +bool DependenceInfo::checkSrcSubscript(const SCEV *Src, const Loop *LoopNest, + SmallBitVector &Loops) { + return checkSubscript(Src, LoopNest, Loops, true); +} // Examine the scev and return true iff it's linear. // Collect any loops mentioned in the set of "Loops". bool DependenceInfo::checkDstSubscript(const SCEV *Dst, const Loop *LoopNest, SmallBitVector &Loops) { - const SCEVAddRecExpr *AddRec = dyn_cast(Dst); - if (!AddRec) - return isLoopInvariant(Dst, LoopNest); - const SCEV *Start = AddRec->getStart(); - const SCEV *Step = AddRec->getStepRecurrence(*SE); - const SCEV *UB = SE->getBackedgeTakenCount(AddRec->getLoop()); - if (!isa(UB)) { - if (SE->getTypeSizeInBits(Start->getType()) < - SE->getTypeSizeInBits(UB->getType())) { - if (!AddRec->getNoWrapFlags()) - return false; - } - } - if (!isLoopInvariant(Step, LoopNest)) - return false; - Loops.set(mapDstLoop(AddRec->getLoop())); - return checkDstSubscript(Start, LoopNest, Loops); + return checkSubscript(Dst, LoopNest, Loops, false); }