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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 02:56:15 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();
----------------
lukel97 wrote:

It will, I just added this here to remove the VPlan diff. I can leave it out if preferred, no strong opinion

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


More information about the llvm-commits mailing list