[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 08:01:07 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:

It looks like that comment was discussing it in the context of reductions.

For any trapping operation, e.g. a load or store, it will be incorrect if we end up with the wrong mask. Which wasn't an issue up until now because we happen to convert loads and stores to vp intrinsics. But if for some reason a load/store slips through optimizeMaskToEVL, then it will be incorrect. I.e. in #150074 

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


More information about the llvm-commits mailing list