[llvm] [LoopVectorize] Improve Vectorization of Low Trip Count Loops (PR #195823)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 01:29:12 PDT 2026


================
@@ -5807,6 +5831,41 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, ElementCount VF,
   return Cost;
 }
 
+bool LoopVectorizationPlanner::isProfitableOneScalarTail(
----------------
sdesmalen-arm wrote:

I don't think there's any need to compare costs; For very-low-trip-count loops (i.e. those that don't meet the tail-folding threshold and have a tail), we want to only consider VF=1, or a VF where TC == VF or TC - 1 == VF. The loop that compares the VF's will always compare the costs against the 'BestVF', which by default is VF=1. So, if this is a very-low-trip-count loop, we can ignore any other VFs, regardless of cost.

That also means you can remove the changes to LoopVectorizationPlanner.

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


More information about the llvm-commits mailing list