[llvm] [VPlan] Convert EVL loops to variable-length stepping after dissolution (PR #147222)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 03:19:43 PDT 2025
================
@@ -2357,6 +2357,71 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
return true;
}
+void VPlanTransforms::simplifyEVLIVs(VPlan &Plan) {
+ using namespace llvm::VPlanPatternMatch;
+ // Find EVL loop entries by locating VPEVLBasedIVPHIRecipe
+ // There should be only one EVL PHI in the entire plan
+ VPEVLBasedIVPHIRecipe *EVLPhi = nullptr;
+
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_shallow(Plan.getEntry())))
+ for (VPRecipeBase &R : VPBB->phis())
+ if (auto *PhiR = dyn_cast<VPEVLBasedIVPHIRecipe>(&R)) {
+ assert(!EVLPhi && "Found multiple EVL PHIs. Only one expected");
+ EVLPhi = PhiR;
+ }
+
+ // Early return if no EVL PHI is found
+ if (!EVLPhi)
+ return;
+
+ VPBasicBlock *Entry = EVLPhi->getParent();
+ VPValue *EVLIncrement = EVLPhi->getBackedgeValue();
+
+ // Convert EVLPhi to concrete recipe.
+ auto *ScalarR =
+ VPBuilder(EVLPhi).createScalarPhi({EVLPhi->getStartValue(), EVLIncrement},
+ EVLPhi->getDebugLoc(), "evl.based.iv");
+ EVLPhi->replaceAllUsesWith(ScalarR);
+ EVLPhi->eraseFromParent();
+
+ // Replace CanonicalIVInc with EVL-PHI increment
+ VPRecipeBase *CanonicalIV = &*Entry->begin();
+ assert(dyn_cast<VPPhi>(CanonicalIV) && "Unexpected canoincal iv");
----------------
fhahn wrote:
This should probably at least also check if the backedge value is `Add, CanonicalIV, VFxUF`
https://github.com/llvm/llvm-project/pull/147222
More information about the llvm-commits
mailing list