[llvm] [VPlan] Move tail folding logic out of addMiddleCheck. NFC (PR #203475)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 02:31:09 PDT 2026


================
@@ -1449,6 +1446,16 @@ void VPlanTransforms::foldTailByMasking(VPlan &Plan) {
         Builder.createNaryOp(VPInstruction::ExtractLane, {LastActiveLane, Op});
     R.getVPSingleValue()->replaceAllUsesWith(Ext);
   }
+
+  // VectorTripCount now equals TripCount so simplify the MiddleVPBB branch.
+  assert(match(Plan.getMiddleBlock()->getTerminator(),
+               m_BranchOnCond(m_OneUse(m_SpecificICmp(
+                   CmpInst::ICMP_EQ, m_Specific(Plan.getTripCount()),
+                   m_Specific(&Plan.getVectorTripCount()))))) &&
+         "Unexpected MiddleVPBB branch");
+  VPValue *OldCond = Plan.getMiddleBlock()->getTerminator()->getOperand(0);
+  Plan.getMiddleBlock()->getTerminator()->setOperand(0, Plan.getTrue());
+  OldCond->getDefiningRecipe()->eraseFromParent();
----------------
artagnon wrote:

Will OldCond not be automatically cleaned up by removeDeadRecipes?

https://github.com/llvm/llvm-project/pull/203475


More information about the llvm-commits mailing list