[llvm] [VPlan] Model branch cond to enter scalar epilogue in VPlan. (PR #92651)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 13:07:47 PDT 2024


================
@@ -815,6 +819,42 @@ VPlanPtr VPlan::createInitialVPlan(const SCEV *TripCount, ScalarEvolution &SE,
   VPBlockUtils::insertBlockAfter(TopRegion, VecPreheader);
   VPBasicBlock *MiddleVPBB = new VPBasicBlock("middle.block");
   VPBlockUtils::insertBlockAfter(MiddleVPBB, TopRegion);
+
+  // Add a check in the middle block to see if we have completed
+  // all of the iterations in the first vector loop.  Three cases:
+  // 1) If we require a scalar epilogue, there is no conditional branch as
+  //    we unconditionally branch to the scalar preheader.  Do nothing.
+  // 2) If (N - N%VF) == N, then we *don't* need to run the remainder.
+  //    Thus if tail is to be folded, we know we don't need to run the
+  //    remainder and we can use the previous value for the condition (true).
+  // 3) Otherwise, construct a runtime check.
+  BasicBlock *IRExitBlock = TheLoop->getUniqueExitBlock();
+  if (RequiresScalarEpilogueCheck) {
+    auto *VPExitBlock = new VPIRBasicBlock(IRExitBlock);
+    VPBlockUtils::insertBlockAfter(VPExitBlock, MiddleVPBB);
----------------
fhahn wrote:

Updated, thanks!

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


More information about the llvm-commits mailing list