diff options
author | Andrey Turetskiy <andrey.turetskiy@gmail.com> | 2016-06-07 14:55:27 +0000 |
---|---|---|
committer | Andrey Turetskiy <andrey.turetskiy@gmail.com> | 2016-06-07 14:55:27 +0000 |
commit | 9f02c586703061b6fa42a36c748306d262b29b97 (patch) | |
tree | ad771eaf885948dac12e4684fdef5c8d7d85ffe5 /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | 953396536b8a1fa1890d2177d1f78fe666e4535a (diff) | |
download | bcm5719-llvm-9f02c586703061b6fa42a36c748306d262b29b97.tar.gz bcm5719-llvm-9f02c586703061b6fa42a36c748306d262b29b97.zip |
[LAA] Improve non-wrapping pointer detection by handling loop-invariant case.
This fixes PR26314. This patch adds new helper “isNoWrap” with detection of
loop-invariant pointer case.
Patch by Roman Shirokiy.
Ref: https://llvm.org/bugs/show_bug.cgi?id=26314
Differential Revision: http://reviews.llvm.org/D17268
llvm-svn: 272014
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index a0df64b4d0a..ff5bc595da5 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -467,7 +467,7 @@ public: /// (i.e. the pointers have computable bounds). bool canCheckPtrAtRT(RuntimePointerChecking &RtCheck, ScalarEvolution *SE, Loop *TheLoop, const ValueToValueMap &Strides, - bool ShouldCheckStride = false); + bool ShouldCheckWrap = false); /// \brief Goes over all memory accesses, checks whether a RT check is needed /// and builds sets of dependent accesses. @@ -551,10 +551,21 @@ static bool hasComputableBounds(PredicatedScalarEvolution &PSE, return AR->isAffine(); } +/// \brief Check whether a pointer address cannot wrap. +static bool isNoWrap(PredicatedScalarEvolution &PSE, + const ValueToValueMap &Strides, Value *Ptr, Loop *L) { + const SCEV *PtrScev = PSE.getSCEV(Ptr); + if (PSE.getSE()->isLoopInvariant(PtrScev, L)) + return true; + + int Stride = getPtrStride(PSE, Ptr, L, Strides); + return Stride == 1; +} + bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck, ScalarEvolution *SE, Loop *TheLoop, const ValueToValueMap &StridesMap, - bool ShouldCheckStride) { + bool ShouldCheckWrap) { // Find pointers with computable bounds. We are going to use this information // to place a runtime bound check. bool CanDoRT = true; @@ -589,8 +600,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck, if (hasComputableBounds(PSE, StridesMap, Ptr, TheLoop) && // When we run after a failing dependency check we have to make sure // we don't have wrapping pointers. - (!ShouldCheckStride || - getPtrStride(PSE, Ptr, TheLoop, StridesMap) == 1)) { + (!ShouldCheckWrap || isNoWrap(PSE, StridesMap, Ptr, TheLoop))) { // The id of the dependence set. unsigned DepId; |