[llvm] [LV] Prefer fixed VFs for epilogue vectorization (PR #211814)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 04:18:22 PDT 2026


================
@@ -706,6 +706,21 @@ bool LoopVectorizationPlanner::isMoreProfitable(const VectorizationFactor &A,
         !B.Width.isScalar())
       return true;
 
+  // Prefer fixed VFs for epilogue loops (unless the fixed cost is much more
+  // expensive -- >= 2x). There are some extra costs for using scalable vectors
+  // in epilogues (e.g., reduced post-vectorization unrolling) that are not
+  // represented in the cost. TODO: Reconsider this restriction for predicated
+  // epilogues (once supported).
+  if (IsEpilogue && A.Width.isScalable() != B.Width.isScalable() &&
+      A.Cost.isValid()) {
+    auto [FixedCost, ScalableCost] = std::make_pair(CostA, CostB);
+    if (B.Width.isFixed())
+      std::swap(FixedCost, ScalableCost);
+
+    if (FixedCost / ScalableCost <= 1)
+      return A.Width.isFixed();
----------------
david-arm wrote:

It took me a while to follow this logic, although I think I understand it now!

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


More information about the llvm-commits mailing list