[llvm] [VPlan] Replace EVL branch condition with (branch-on-count AVLNext, 0) (PR #152167)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 21 02:05:08 PDT 2025
================
@@ -2447,19 +2447,43 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
// Find EVL loop entries by locating VPEVLBasedIVPHIRecipe.
// There should be only one EVL PHI in the entire plan.
VPEVLBasedIVPHIRecipe *EVLPhi = nullptr;
+ VPValue *AVLNext = nullptr;
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
vp_depth_first_shallow(Plan.getEntry())))
- for (VPRecipeBase &R : VPBB->phis())
- if (auto *PhiR = dyn_cast<VPEVLBasedIVPHIRecipe>(&R)) {
+ for (VPRecipeBase &R : VPBB->phis()) {
+ auto *PhiR = dyn_cast<VPSingleDefRecipe>(&R);
+ if (!PhiR)
+ continue;
+ VPValue *Backedge;
+ if (auto *EVL = dyn_cast<VPEVLBasedIVPHIRecipe>(PhiR)) {
assert(!EVLPhi && "Found multiple EVL PHIs. Only one expected");
- EVLPhi = PhiR;
+ EVLPhi = EVL;
+ continue;
+ }
+ if (match(PhiR,
+ m_VPInstruction<Instruction::PHI>(
+ m_Specific(Plan.getTripCount()), m_VPValue(Backedge))) &&
+ match(Backedge,
+ m_VPInstruction<Instruction::Sub>(
+ m_Specific(PhiR),
+ m_ZExtOrSelf(
+ m_VPInstruction<VPInstruction::ExplicitVectorLength>(
+ m_CombineOr(
+ m_Specific(PhiR),
+ // The AVL may be capped to a safe distance.
+ m_Select(m_VPValue(), m_Specific(PhiR),
+ m_VPValue()))))))) {
----------------
artagnon wrote:
Hm, this seems like a very specific pattern, and I wonder if this is fragile?
https://github.com/llvm/llvm-project/pull/152167
More information about the llvm-commits
mailing list