[llvm] [VPlan] Fix header masks in EVL tail folding (PR #150202)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 06:09:04 PDT 2025


================
@@ -2265,6 +2269,27 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
     for (VPValue *Op : PossiblyDead)
       recursivelyDeleteDeadRecipes(Op);
   }
+
+  // Replace header masks with a mask equivalent to predicating by EVL:
+  //
+  // icmp ule widen-canonical-iv backedge-taken-count
+  // ->
+  // icmp ult step-vector, EVL
+  Type *EVLType = TypeInfo.inferScalarType(&EVL);
----------------
lukel97 wrote:

> So this is needed for correctness, right? Should it not happen before the loop above?

It should, but we need to rework that optimizeMaskToEVL loop to detect EVL style header masks. I was hoping to do that in a separate NFC patch, but can include it in this one if you'd like.

> Also, inferring type after removing recipes? Should this happen before for (VPRecipeBase *R : reverse(ToErase)) {?

Yes good catch, I had pulled EVLType out of the loop so it wouldn't be invalidated when calling `HeaderMask->getDefiningRecipe()->eraseFromParent()`, but forgot about the erasing above :)

https://github.com/llvm/llvm-project/pull/150202


More information about the llvm-commits mailing list