[llvm] [LAA] Rewrite findForkedPointer (NFCI) (PR #140298)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue May 20 05:29:41 PDT 2025
================
@@ -1088,29 +1092,49 @@ static void findForkedSCEVs(
}
}
-static SmallVector<PointerIntPair<const SCEV *, 1, bool>>
-findForkedPointer(PredicatedScalarEvolution &PSE,
- const DenseMap<Value *, const SCEV *> &StridesMap, Value *Ptr,
- const Loop *L) {
- ScalarEvolution *SE = PSE.getSE();
- assert(SE->isSCEVable(Ptr->getType()) && "Value is not SCEVable!");
- 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.
- if (Scevs.size() == 2 &&
----------------
fhahn wrote:
Rigth, this wasnt related to the freeze issue, but the current code should reject if we have forked pointers that result in more than 2 SCEVs. I think there might be test coverage missing for the case, as there are no test failures when doing something like
```
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 2a322a69a0db..7a7f1c68d8fe 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1099,18 +1099,20 @@ findForkedPointer(PredicatedScalarEvolution &PSE,
// For now, we will only accept a forked pointer with two possible SCEVs
// that are either SCEVAddRecExprs or loop invariant.
- if (Scevs.size() == 2 &&
- (isa<SCEVAddRecExpr>(get<0>(Scevs[0])) ||
- SE->isLoopInvariant(get<0>(Scevs[0]), L)) &&
- (isa<SCEVAddRecExpr>(get<0>(Scevs[1])) ||
+ if (Scevs.size() < 2)
+ return {{replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr), false}};
+ if (
+ !(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))) {
+ return {{replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr), 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");
return Scevs;
- }
- return {{replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr), false}};
}
bool AccessAnalysis::createCheckForAccess(
```
https://github.com/llvm/llvm-project/pull/140298
More information about the llvm-commits
mailing list