[llvm] [LoopVectorize] Improve Vectorization of Low Trip Count Loops (PR #195823)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 00:48:10 PDT 2026
================
@@ -3068,6 +3068,27 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
}
}
+ // Allow cases where the ExactTC == (VF * IC) + 1.
+ //
+ // This produces 1 vector iteration, and 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.
+ ElementCount ExactTC = getSmallConstantTripCount(PSE.getSE(), TheLoop);
+ unsigned TC = ExactTC.getFixedValue();
+ unsigned MyMaxVF = 1ULL << Log2_32(TC);
+ unsigned EffectiveIC = UserIC > 0 ? UserIC : 1;
+ if (TC - MyMaxVF == 1 && !TheFunction->hasOptSize() && !Config.OptForSize) {
----------------
sdesmalen-arm wrote:
```suggestion
if (TC - MyMaxVF <= 1 && !TheFunction->hasOptSize() && !Config.OptForSize) {
```
Is there a reason to explicitly disallow the case where the tripcount is exactly VF * IC (without an additional scalar iteration)?
https://github.com/llvm/llvm-project/pull/195823
More information about the llvm-commits
mailing list