[llvm] [VPlan] Replace EVL branch condition with (branch-on-count AVLNext, 0) (PR #152167)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 21 05:23:44 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()))))))) {
----------------
lukel97 wrote:
Yeah it's quite a specific pattern but every EVL loop needs to be in this format by definition.
I took the opportunity though to simplify it and instead find the backedge via the EVL based PHI, it should be simpler now.
https://github.com/llvm/llvm-project/pull/152167
More information about the llvm-commits
mailing list