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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 01:58: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() &&
----------------
david-arm wrote:

Yeah it's a good point. It's possible that the changes to `preferFixedOverScalableIfEqualCost` happened before the changes to permit more cost kinds and simply wasn't updated at the time. All I was trying to say is that if the goal is to reduce code size then we might want the lowest cost possible, which may be the scalable VF. Currently with this change we'll favour a fixed width VF with cost 2 over a scalable VF with cost 1.5, etc. I suppose you could also argue that for LTO optimisations the fixed-width VF still makes sense from a code size perspective if discovering the trip count allows you to delete the vector epilogue. I can see arguments either way and I'll leave it your judgement!

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


More information about the llvm-commits mailing list