[llvm] [LV] Support tail-folded epilogue loops (PR #208764)

Hassnaa Hamdi via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 10:46:23 PDT 2026


================
@@ -7554,6 +7697,23 @@ static SmallVector<Instruction *> preparePlanForEpilogueVectorLoop(
           continue;
         }
       }
+    } else if (isa<VPActiveLaneMaskPHIRecipe>(&R)) {
+      // The active-lane-mask phi's entry value was computed assuming the
+      // epilogue vector loop starts at 0. Rebuild it using the resume value
+      // instead, so the mask reflects how many elements the main vector loop
+      // already processed.
+      VPBuilder EntryBuilder(Plan.getVectorPreheader());
+      Type *CanIVTy = VectorLoop->getCanonicalIVType();
+      VPValue *ALMMultiplier = Plan.getConstantInt(CanIVTy, 1);
+      auto *EntryIncrement = EntryBuilder.createOverflowingOp(
+          VPInstruction::CanonicalIVIncrementForPart, {VPV, &Plan.getVF()}, {},
+          R.getDebugLoc(), "index.part.next");
+      auto *EntryALM = EntryBuilder.createNaryOp(
+          VPInstruction::WideActiveLaneMask,
----------------
hassnaaHamdi wrote:

For RISCV, it doesn't prefer epilogues, so this feature is not supported for it. I'll add a patch to provide tests for it.

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


More information about the llvm-commits mailing list