[llvm] [LoopVectorize] Improve Vectorization of Low Trip Count Loops (PR #195823)
Jack Styles via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 01:13:41 PDT 2026
================
@@ -3066,6 +3071,36 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
}
}
+ // Allow cases where the ExactTC == (VF * IC) or ExactTC == (VF * IC) + 1.
+ //
+ // This produces at most 1 vector iteration, and at most 1 scalar iteration
+ // with no remainder. Later passes will eliminate the loop and leave
+ // straight-line code as the both iteration counts are statically known.
+ //
+ // If a function is marked as minsize/optsize or OptForSize is set, do not
+ // allow this form of transformation as this will increase CodeSize.
+ //
+ // For loops with small bodies, the cost model is not currently reliable
+ // enough to accurately determine if vectorization is beneficial.
+ unsigned EffectiveIC = UserIC > 0 ? UserIC : 1;
+ unsigned MaxVFForTC = llvm::bit_floor(TC.getFixedValue());
+ if (TC.getFixedValue() - MaxVFForTC <= 1 && MaxVFForTC / EffectiveIC > 1 &&
----------------
Stylie777 wrote:
I disagree, as I mentioned in #225633 I think it would be better to avoid limit it to situations where the Loop Latch is in the Loop Exiting Block. I think limiting this to where we have a scalar iteration is too limiting. See #225635.
https://github.com/llvm/llvm-project/pull/195823
More information about the llvm-commits
mailing list