[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:21:49 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);
+ for (VPValue *HeaderMask : collectAllHeaderMasks(Plan)) {
+ if (HeaderMask->users().empty())
+ continue;
+ VPRecipeBase *EVLR = EVL.getDefiningRecipe();
+ VPBuilder Builder(Plan.getVectorPreheader());
+ VPValue *StepVector =
+ Builder.createNaryOp(VPInstruction::StepVector, {}, EVLType);
+ Builder.setInsertPoint(EVLR->getParent(), std::next(EVLR->getIterator()));
+ VPValue *EVLMask = Builder.createICmp(
+ CmpInst::ICMP_ULT, StepVector,
+ Builder.createNaryOp(VPInstruction::Broadcast, {&EVL}));
----------------
lukel97 wrote:
We hit the `"scalar value but not only first lane defined"` assertion without it when generating EVL, but now that you mention it I think we just need to add `VPInstruction::ExplicitVectorLength` to `VPInstruction::isSingleScalar`. I can split that off into a separate PR if you'd like
https://github.com/llvm/llvm-project/pull/150202
More information about the llvm-commits
mailing list