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

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 16 16:24:36 PDT 2024


================
@@ -795,6 +833,35 @@ VPlanPtr VPlan::createInitialVPlan(const SCEV *TripCount, ScalarEvolution &SE,
   VPBlockUtils::insertBlockAfter(TopRegion, VecPreheader);
   VPBasicBlock *MiddleVPBB = new VPBasicBlock("middle.block");
   VPBlockUtils::insertBlockAfter(MiddleVPBB, TopRegion);
+
+  BasicBlock *EB = TheLoop->getUniqueExitBlock();
+  if (RequiresScalarEpilogueCheck) {
+    auto *EBWrapper = new VPIRBasicBlock(EB);
+    VPBlockUtils::insertBlockAfter(EBWrapper, MiddleVPBB);
+
+    auto *ScalarLatchTerm = TheLoop->getLoopLatch()->getTerminator();
+    // Here we use the same DebugLoc as the scalar loop latch terminator instead
+    // of the corresponding compare because they may have ended up with
+    // different line numbers and we want to avoid awkward line stepping while
+    // debugging. Eg. if the compare has got a line number inside the loop.
+    VPValue *Cmp =
+        TailFolded
+            ? Plan->getOrAddLiveIn(ConstantInt::getTrue(
+                  IntegerType::getInt1Ty(TripCount->getType()->getContext())))
----------------
ayalz wrote:

There are three cases, as follow. They can be optimized later (some sub-cases once VFxUF is set), possibly using an unconditional branch  VPInstruction, based on an initial conditional branch checking leftover iterations ("else" case below, always correct), here in createInitialVPlan(), instead a redundant `if true` placeholder?
1. NoTail --> middle goes to exit only
   - TailFolded, OR
   - vector trip count known to be a multiple of VFxUF
2. MustTail --> middle goes to scalar preheader only
   - RequiresScalarEpilogue, OR
   - vector trip count known to not be a multiple of VFxUF
3. MayTail (else) --> middle goes to either exit or scalar preheader based on leftover iterations check

Or have the initial/canonical case be with tail folded, as outlined in the roadmap, with possible tail unfolding followed by possible epilog vectorization etc.

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


More information about the llvm-commits mailing list