[llvm] [VPlan] Replace BranchOnCount with Compare + BranchOnCond (NFC). (PR #172181)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 13 22:02:24 PST 2025
================
@@ -3201,27 +3201,25 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
CanonicalIV->eraseFromParent();
// Replace the use of VectorTripCount in the latch-exiting block.
- // Before: (branch-on-count EVLIVInc, VectorTripCount)
- // After: (branch-on-cond eq AVLNext, 0)
-
+ // Before: (branch-on-cond (icmp eq EVLIVInc, VectorTripCount))
+ // After: (branch-on-cond icmp eq AVLNext, 0)
VPBasicBlock *LatchExiting =
HeaderVPBB->getPredecessors()[1]->getEntryBasicBlock();
auto *LatchExitingBr = cast<VPInstruction>(LatchExiting->getTerminator());
- // Skip single-iteration loop region
if (match(LatchExitingBr, m_BranchOnCond(m_True())))
return;
- assert(LatchExitingBr &&
- match(LatchExitingBr,
- m_BranchOnCount(m_VPValue(EVLIncrement),
- m_Specific(&Plan.getVectorTripCount()))) &&
- "Unexpected terminator in EVL loop");
+
+ assert(match(LatchExitingBr, m_BranchOnCond(m_SpecificCmp(
+ CmpInst::ICMP_EQ, m_VPValue(EVLIncrement),
+ m_Specific(&Plan.getVectorTripCount())))) &&
+ "Expected BranchOnCond with ICmp comparing EVL increment with vector "
+ "trip count");
Type *AVLTy = VPTypeAnalysis(Plan).inferScalarType(AVLNext);
VPBuilder Builder(LatchExitingBr);
- VPValue *Cmp = Builder.createICmp(CmpInst::ICMP_EQ, AVLNext,
- Plan.getConstantInt(AVLTy, 0));
- Builder.createNaryOp(VPInstruction::BranchOnCond, Cmp);
- LatchExitingBr->eraseFromParent();
+ LatchExitingBr->setOperand(0,
+ Builder.createICmp(CmpInst::ICMP_EQ, AVLNext,
+ Plan.getConstantInt(AVLTy, 0)));
----------------
lukel97 wrote:
I think this will leave behind a potentially dead icmp but that should be ok since we run removeDeadRecipes afterwards?
https://github.com/llvm/llvm-project/pull/172181
More information about the llvm-commits
mailing list