[llvm] [LAA][NFCI] Re-use hasComputableBounds in findForkedPointer and refactor createCheckForAccess (PR #112571)
Sergey Kachkov via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 09:02:37 PDT 2024
https://github.com/skachkov-sc created https://github.com/llvm/llvm-project/pull/112571
Splitted from #106574.
>From 39e56a075f3bc5fba4ecaba9759148cd2a3c17fb Mon Sep 17 00:00:00 2001
From: Sergey Kachkov <sergey.kachkov at syntacore.com>
Date: Tue, 27 Aug 2024 17:48:02 +0300
Subject: [PATCH] [LAA][NFCI] Re-use hasComputableBounds in findForkedPointer
and refactor createCheckForAccess
---
llvm/lib/Analysis/LoopAccessAnalysis.cpp | 40 ++++++++++--------------
1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index d35bf6818d4379..9ca87aa81197c9 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -807,7 +807,8 @@ class AccessAnalysis {
/// If \p Assume, try harder to prove that we can compute the bounds of \p Ptr
/// by adding run-time checks (overflow checks) if necessary.
static bool hasComputableBounds(PredicatedScalarEvolution &PSE, Value *Ptr,
- const SCEV *PtrScev, Loop *L, bool Assume) {
+ const SCEV *PtrScev, const Loop *L,
+ bool Assume) {
// The bounds for loop-invariant pointer is trivial.
if (PSE.getSE()->isLoopInvariant(PtrScev, L))
return true;
@@ -1039,13 +1040,10 @@ findForkedPointer(PredicatedScalarEvolution &PSE,
SmallVector<PointerIntPair<const SCEV *, 1, bool>> Scevs;
findForkedSCEVs(SE, L, Ptr, Scevs, MaxForkedSCEVDepth);
- // For now, we will only accept a forked pointer with two possible SCEVs
- // that are either SCEVAddRecExprs or loop invariant.
+ // For now, we will only accept a forked pointer with two possible SCEVs.
if (Scevs.size() == 2 &&
- (isa<SCEVAddRecExpr>(get<0>(Scevs[0])) ||
- SE->isLoopInvariant(get<0>(Scevs[0]), L)) &&
- (isa<SCEVAddRecExpr>(get<0>(Scevs[1])) ||
- SE->isLoopInvariant(get<0>(Scevs[1]), L))) {
+ hasComputableBounds(PSE, Ptr, get<0>(Scevs[0]), L, /*Assume*/ false) &&
+ hasComputableBounds(PSE, Ptr, get<0>(Scevs[1]), L, /*Assume*/ false)) {
LLVM_DEBUG(dbgs() << "LAA: Found forked pointer: " << *Ptr << "\n");
LLVM_DEBUG(dbgs() << "\t(1) " << *get<0>(Scevs[0]) << "\n");
LLVM_DEBUG(dbgs() << "\t(2) " << *get<0>(Scevs[1]) << "\n");
@@ -1067,30 +1065,26 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
SmallVector<PointerIntPair<const SCEV *, 1, bool>> TranslatedPtrs =
findForkedPointer(PSE, StridesMap, Ptr, TheLoop);
- for (const auto &P : TranslatedPtrs) {
- const SCEV *PtrExpr = get<0>(P);
- if (!hasComputableBounds(PSE, Ptr, PtrExpr, TheLoop, Assume))
+ if (TranslatedPtrs.size() == 1) {
+ auto &TranslatedPtr = TranslatedPtrs.front();
+ if (!hasComputableBounds(PSE, Ptr, get<0>(TranslatedPtr), TheLoop, Assume))
return false;
// When we run after a failing dependency check we have to make sure
// we don't have wrapping pointers.
- if (ShouldCheckWrap) {
- // Skip wrap checking when translating pointers.
- if (TranslatedPtrs.size() > 1)
+ if (ShouldCheckWrap && !isNoWrap(PSE, StridesMap, Ptr, AccessTy, TheLoop)) {
+ const SCEV *Expr = PSE.getSCEV(Ptr);
+ if (!Assume || !isa<SCEVAddRecExpr>(Expr))
return false;
-
- if (!isNoWrap(PSE, StridesMap, Ptr, AccessTy, TheLoop)) {
- const SCEV *Expr = PSE.getSCEV(Ptr);
- if (!Assume || !isa<SCEVAddRecExpr>(Expr))
- return false;
- PSE.setNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW);
- }
+ PSE.setNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW);
}
// If there's only one option for Ptr, look it up after bounds and wrap
// checking, because assumptions might have been added to PSE.
- if (TranslatedPtrs.size() == 1)
- TranslatedPtrs[0] = {replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr),
- false};
+ TranslatedPtr = {replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr), false};
+ } else {
+ // Skip wrap checking when translating pointers.
+ if (ShouldCheckWrap)
+ return false;
}
for (auto [PtrExpr, NeedsFreeze] : TranslatedPtrs) {
More information about the llvm-commits
mailing list