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

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 07:54:08 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);
----------------
Mel-Chen wrote:

> So this is needed for correctness, right? Should it not happen before the loop above?
> 
I remember we discussed this issue a long time ago: https://github.com/llvm/llvm-project/pull/90184#discussion_r1637795282
It doesn’t seem like a correctness issue — unless I missed some cases?
Anyway, I noticed that some test case did get fewer IR, so this seems like a good direction overall, I think.


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


More information about the llvm-commits mailing list