[llvm] [VPlan] Unify inner and outer loop paths (NFCI). (PR #192868)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 19 13:20:18 PDT 2026
================
@@ -7657,30 +7646,38 @@ VPRecipeBuilder::tryToCreateWidenNonPhiRecipe(VPSingleDefRecipe *R,
// optimizations.
static void printOptimizedVPlan(VPlan &) {}
-void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
- ElementCount MaxVF) {
+void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF,
+ ElementCount MaxVF) {
if (ElementCount::isKnownGT(MinVF, MaxVF))
return;
- assert(OrigLoop->isInnermost() && "Inner loop expected.");
-
- const LoopAccessInfo *LAI = Legal->getLAI();
- LoopVersioning LVer(*LAI, LAI->getRuntimePointerChecking()->getChecks(),
- OrigLoop, LI, DT, PSE.getSE());
- if (!LAI->getRuntimePointerChecking()->getChecks().empty() &&
- !LAI->getRuntimePointerChecking()->getDiffChecks()) {
- // Only use noalias metadata when using memory checks guaranteeing no
- // overlap across all iterations.
- LVer.prepareNoAliasMetadata();
+ bool IsInnerLoop = OrigLoop->isInnermost();
+
+ // Set up loop versioning for inner loops with memory runtime checks.
+ // Outer loops don't have LoopAccessInfo since canVectorizeMemory() is not
+ // called for them.
+ std::optional<LoopVersioning> LVer;
+ if (IsInnerLoop) {
+ const LoopAccessInfo *LAI = Legal->getLAI();
+ LVer.emplace(*LAI, LAI->getRuntimePointerChecking()->getChecks(), OrigLoop,
+ LI, DT, PSE.getSE());
+ if (!LAI->getRuntimePointerChecking()->getChecks().empty() &&
+ !LAI->getRuntimePointerChecking()->getDiffChecks()) {
+ // Only use noalias metadata when using memory checks guaranteeing no
+ // overlap across all iterations.
+ LVer->prepareNoAliasMetadata();
+ }
}
// Create initial base VPlan0, to serve as common starting point for all
// candidates built later for specific VF ranges.
auto VPlan0 = VPlanTransforms::buildVPlan0(
OrigLoop, *LI, Legal->getWidestInductionType(),
- getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE, &LVer);
+ getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE,
+ LVer ? &*LVer : nullptr);
----------------
artagnon wrote:
```suggestion
LVer);
```
Hm, would be better to refactor buildVPlan0 to take an optional LVer, and land that change independently?
https://github.com/llvm/llvm-project/pull/192868
More information about the llvm-commits
mailing list