[llvm] [VPlan] Split out optimizeEVLMasks. NFC (PR #174925)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 10 13:14:37 PST 2026
================
@@ -2979,8 +2979,43 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
return nullptr;
}
-/// Replace recipes with their EVL variants.
-static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
+/// Optimize away any EVL-based header masks to VP intrinsic based recipes.
+/// The transforms here need to preserve the original semantics.
+void VPlanTransforms::optimizeEVLMasks(VPlan &Plan) {
+ // Find the EVL-based header mask if it exists: icmp ult step-vector, EVL
+ VPValue *HeaderMask = nullptr, *EVL = nullptr;
+ for (VPRecipeBase &R : *Plan.getVectorLoopRegion()->getEntryBasicBlock()) {
+ if (match(&R, m_SpecificICmp(CmpInst::ICMP_ULT, m_StepVector(),
+ m_VPValue(EVL))) &&
+ match(EVL, m_EVL(m_VPValue()))) {
+ HeaderMask = R.getVPSingleValue();
+ break;
+ }
+ }
+ if (!HeaderMask)
+ return;
+
+ VPTypeAnalysis TypeInfo(Plan);
+ SmallVector<VPRecipeBase *> OldRecipes;
+ for (VPUser *U : collectUsersRecursively(HeaderMask)) {
+ VPRecipeBase *R = cast<VPRecipeBase>(U);
+ if (auto *NewR = optimizeMaskToEVL(HeaderMask, *R, TypeInfo, *EVL)) {
+ NewR->insertBefore(R);
+ for (auto [Old, New] :
+ zip_equal(R->definedValues(), NewR->definedValues()))
+ Old->replaceAllUsesWith(New);
+ OldRecipes.push_back(R);
+ }
+ }
+ // Erase recipes at the end so we don't invalidate TypeInfo.
+ for (VPRecipeBase *OldR : OldRecipes)
+ OldR->eraseFromParent();
+ removeDeadRecipes(Plan);
+}
+
+/// After replacing the IV with a EVL-based IV, fixup recipes that use VF to use
----------------
fhahn wrote:
```suggestion
/// After replacing the canonical IV with a EVL-based IV, fixup recipes that use VF to use
```
https://github.com/llvm/llvm-project/pull/174925
More information about the llvm-commits
mailing list