[llvm] [LV] Add -fold-epilogue-tail option for tail-folded epilogue (PR #190697)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 05:01:14 PDT 2026
================
@@ -7557,6 +7583,43 @@ getEpilogueLowering(Function *F, Loop *L, LoopVectorizeHints &Hints,
return CM_EpilogueAllowed;
}
+/// Determine how to lower the epilogue for the vector epilogue loop.
+/// Check if there are any conflicts that prevent tail-folding the epilogue.
+/// \return CM_EpilogueNotNeededFoldEpilogueTail if epilogue tail-folding
+/// is possible, otherwise CM_EpilogueAllowed.
+static EpilogueLowering
+getEpilogueTailLowering(const LoopVectorizationCostModel &CM) {
+ // Epilogue TF is only enabled when explicitly requested via command line.
+ if (TailFoldingPolicy != TailFoldingPolicyTy::PreferFoldEpilogueTail)
+ // fallback to a normal epilogue.
+ return CM_EpilogueAllowed;
+
+ if (!EnableEpilogueVectorization) {
+ LLVM_DEBUG(dbgs() << "LV: Options conflict, epilogue vectorization is "
+ "disallowed while epilogue tail-folding allowed!\n");
+ LLVM_DEBUG(dbgs() << "LV: Fallback to a normal epilogue\n");
+ return CM_EpilogueAllowed;
+ }
+
+ // If scalar epilogue is explicitly required, we can't apply TF.
+ if (CM.requiresScalarEpilogue(/*IsVectorizing*/ true)) {
+ LLVM_DEBUG(dbgs() << "LV: Epilogue tail-folding can't be applied because "
+ "scalar epilogue is required\n");
+ LLVM_DEBUG(dbgs() << "LV: Fallback to a normal epilogue\n");
+ return CM_EpilogueAllowed;
+ }
+
+ // If having epilogue is NOT allowed, then no epilogue to apply TF for.
+ if (!CM.isEpilogueAllowed()) {
+ LLVM_DEBUG(dbgs() << "LV: No epilogue to apply tail-folding for.\n");
+ LLVM_DEBUG(dbgs() << "LV: Fallback to a normal epilogue\n");
----------------
david-arm wrote:
nit: Perhaps combine two LLVM_DEBUG calls into one, i.e.
```
LLVM_DEBUG(dbgs() << "LV: No epilogue to apply tail-folding for.\n"
<< "LV: Fallback to a normal epilogue\n");
```
https://github.com/llvm/llvm-project/pull/190697
More information about the llvm-commits
mailing list