[llvm] [LV] Fold middle-block branch in post-dissolution removeBranchOnConst. (PR #204243)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 07:23:57 PDT 2026


================
@@ -5974,20 +5974,21 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
   RUN_VPLAN_PASS(VPlanTransforms::expandBranchOnTwoConds, BestVPlan);
   // Convert loops with variable-length stepping after regions are dissolved.
   RUN_VPLAN_PASS(VPlanTransforms::convertToVariableLengthStep, BestVPlan);
-  // Remove dead back-edges for single-iteration loops with BranchOnCond(true).
-  // Only process loop latches to avoid removing edges from the middle block,
-  // which may be needed for epilogue vectorization.
-  VPlanTransforms::removeBranchOnConst(BestVPlan, /*OnlyLatches=*/true);
-  VPlanTransforms::materializeBackedgeTakenCount(BestVPlan, VectorPH);
-  std::optional<uint64_t> MaxRuntimeStep;
-  if (auto MaxVScale = getMaxVScale(*CM.TheFunction, CM.TTI))
-    MaxRuntimeStep = uint64_t(*MaxVScale) * BestVF.getKnownMinValue() * BestUF;
-  assert((OrigLoop->getUniqueLatchExitBlock() || RequiresScalarEpilogue) &&
-         "loops not exiting via the latch without required epilogue?");
-  VPlanTransforms::materializeVectorTripCount(
-      BestVPlan, VectorPH, HasTailFolded, RequiresScalarEpilogue,
-      &BestVPlan.getVFxUF(), MaxRuntimeStep);
-  VPlanTransforms::materializeFactors(BestVPlan, VectorPH, BestVF);
+
+  // Fold any remaining BranchOnCond with constant condition.
+  VPlanTransforms::removeBranchOnConst(BestVPlan, /*OnlyLatches=*/false);
+  if (VectorPH->hasPredecessors()) {
----------------
david-arm wrote:

If I understand correctly, the only way the vector preheader can have no predecessors is if a scevcheck or memcheck block has been optimised to completely skip the vector loop?

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


More information about the llvm-commits mailing list