aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopAccessAnalysis.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2020-05-27 12:19:22 +0100
committerFlorian Hahn <flo@fhahn.com>2020-05-27 12:37:20 +0100
commit259abfc7cbc11cd98c05b1eb8e4b3fb6a9664bc0 (patch)
treeecda1d9cb06c01bee76526efe85e390afd203255 /llvm/lib/Analysis/LoopAccessAnalysis.cpp
parent706b22e3e446621b20befe1094c26e4eda133bc9 (diff)
downloadllvm-259abfc7cbc11cd98c05b1eb8e4b3fb6a9664bc0.zip
llvm-259abfc7cbc11cd98c05b1eb8e4b3fb6a9664bc0.tar.gz
llvm-259abfc7cbc11cd98c05b1eb8e4b3fb6a9664bc0.tar.bz2
[LAA] We only need pointer checks if there are non-zero checks (NFC).
If it turns out that we can do runtime checks, but there are no runtime-checks to generate, set RtCheck.Need to false. This can happen if we can prove statically that the pointers passed in to canCheckPtrAtRT do not alias. This should not change any results, but allows us to skip some work and assert that runtime checks are generated, if LAA indicates that runtime checks are required. Reviewers: anemet, Ayal Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D79969
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/LoopAccessAnalysis.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 014cabd..6e1217f 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -701,12 +701,14 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
ScalarEvolution *SE, Loop *TheLoop,
const ValueToValueMap &StridesMap,
bool ShouldCheckWrap) {
+ if (!IsRTCheckAnalysisNeeded)
+ return true;
+
// Find pointers with computable bounds. We are going to use this information
// to place a runtime bound check.
bool CanDoRT = true;
- bool NeedRTCheck = false;
- if (!IsRTCheckAnalysisNeeded) return true;
+ RtCheck.Need = false;
bool IsDepCheckNeeded = isDependencyCheckNeeded();
@@ -747,10 +749,10 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
// check them. But there is no need to checks if there is only one
// dependence set for this alias set.
//
- // Note that this function computes CanDoRT and NeedRTCheck independently.
- // For example CanDoRT=false, NeedRTCheck=false means that we have a pointer
- // for which we couldn't find the bounds but we don't actually need to emit
- // any checks so it does not matter.
+ // Note that this function computes CanDoRT and RtCheck.Need independently.
+ // For example CanDoRT=false, RtCheck.Need=false means that we have a
+ // pointer for which we couldn't find the bounds but we don't actually need
+ // to emit any checks so it does not matter.
bool NeedsAliasSetRTCheck = false;
if (!(IsDepCheckNeeded && CanDoAliasSetRT && RunningDepId == 2))
NeedsAliasSetRTCheck = (NumWritePtrChecks >= 2 ||
@@ -773,7 +775,7 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
}
CanDoRT &= CanDoAliasSetRT;
- NeedRTCheck |= NeedsAliasSetRTCheck;
+ RtCheck.Need |= NeedsAliasSetRTCheck;
++ASId;
}
@@ -807,15 +809,19 @@ bool AccessAnalysis::canCheckPtrAtRT(RuntimePointerChecking &RtCheck,
}
}
- if (NeedRTCheck && CanDoRT)
+ if (RtCheck.Need && CanDoRT)
RtCheck.generateChecks(DepCands, IsDepCheckNeeded);
LLVM_DEBUG(dbgs() << "LAA: We need to do " << RtCheck.getNumberOfChecks()
<< " pointer comparisons.\n");
- RtCheck.Need = NeedRTCheck;
+ // If we can do run-time checks, but there are no checks, no runtime checks
+ // are needed. This can happen when all pointers point to the same underlying
+ // object for example.
+ if (CanDoRT)
+ RtCheck.Need = RtCheck.getNumberOfChecks() != 0;
- bool CanDoRTIfNeeded = !NeedRTCheck || CanDoRT;
+ bool CanDoRTIfNeeded = !RtCheck.Need || CanDoRT;
if (!CanDoRTIfNeeded)
RtCheck.reset();
return CanDoRTIfNeeded;