[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
================
@@ -5895,6 +5961,19 @@ LoopVectorizationPlanner::computeBestVF() {
cost(*P, VF, ConsiderRegPressure ? &RUs[I] : nullptr);
VectorizationFactor CurrentFactor(VF, Cost, ScalarCost);
+ unsigned int UserIC =
+ Hints.getInterleave() != 0 ? Hints.getInterleave() : 1;
+ if (!ForceVectorization && P->hasScalarTail() &&
+ shouldConsiderOneScalarTail(CurrentFactor, ExactTC, UserIC) &&
+ isProfitableOneScalarTail(CurrentFactor, ExactTC, UserIC)) {
+ // If we have identified a case where a small trip count loop can
+ // be Vectorized as one Vector Iteration and, if needed, one scalar
+ // iteration, use this VF and break.
+ BestFactor = CurrentFactor;
+ PlanForBestVF = P.get();
+ break;
+ }
----------------
sdesmalen-arm wrote:
Given that the only supported VF's for this case is MaxVF (see my comment above on `isProfitableOneScalarTail`), you could also prune `VFs` to contain only the maximum VF (i.e. pick the last one), when this is a very-low-tripcount loop and the plan has a tail.
https://github.com/llvm/llvm-project/pull/195823
More information about the llvm-commits
mailing list