[llvm] [VPlan] Introduce generic variable-length step support (PR #177114)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 4 01:33:41 PST 2026
================
@@ -3240,89 +3224,135 @@ void VPlanTransforms::addExplicitVectorLength(
removeDeadRecipes(Plan);
// Replace all uses of VPCanonicalIVPHIRecipe by
- // VPEVLBasedIVPHIRecipe except for the canonical IV increment.
- CanonicalIVPHI->replaceAllUsesWith(EVLPhi);
+ // VPCumulativeIVPHIRecipe except for the canonical IV increment.
+ CanonicalIVPHI->replaceAllUsesWith(CumulativeIVPhi);
CanonicalIVIncrement->setOperand(0, CanonicalIVPHI);
+
// TODO: support unroll factor > 1.
Plan.setUF(1);
+
+ // Switch the loop from up-counting to down counting.
+ // convert (branch-on-count (CanonicalInc, VTC)
+ // -> (branch-on-count (sub VTC, CanonicalIVInc), 0)
+ VPBasicBlock *LatchVPBB = LoopRegion->getExitingBasicBlock();
+ auto *LatchExitingBranch = cast<VPInstruction>(LatchVPBB->getTerminator());
+ if (match(LatchExitingBranch, m_BranchOnCond(m_True())))
+ return;
+ assert(match(LatchExitingBranch,
+ m_BranchOnCount(m_Specific(CanonicalIVIncrement),
+ m_Specific(&Plan.getVectorTripCount()))) &&
+ "Unexpected terminator");
+ Builder.setInsertPoint(LatchExitingBranch);
+ VPValue *RemainElementCount = Builder.createOverflowingOp(
+ Instruction::Sub, {&Plan.getVectorTripCount(), CanonicalIVIncrement},
+ {/*hasNUW=*/true, /*hasNSW=*/false}, DebugLoc::getCompilerGenerated(),
+ "remain.element.count");
+ auto *Zero = Plan.getOrAddLiveIn(ConstantInt::get(CanIVTy, 0));
+ LatchExitingBranch->setOperand(0, RemainElementCount);
+ LatchExitingBranch->setOperand(1, Zero);
----------------
arcbbb wrote:
Thanks for #178181! That makes this an NFC now.
https://github.com/llvm/llvm-project/pull/177114
More information about the llvm-commits
mailing list