[llvm] [LoopVectorize] Improve Vectorization of Low Trip Count Loops (PR #195823)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 06:15:05 PDT 2026
================
@@ -6134,6 +6198,40 @@ LoopVectorizationPlanner::computeBestVF() {
}
VPlan *PlanForBestVF = &FirstPlan;
+ ElementCount ExactTC = getSmallConstantTripCount(PSE.getSE(), OrigLoop);
+ auto IsUnprofitableOneScalarTail =
+ [&](const VectorizationFactor &CurrentFactor, bool HasTail) {
+ if (ForceVectorization || !HasTail || !ExactTC.isFixed() ||
+ CurrentFactor.Width.isScalable())
+ return false;
+
+ unsigned TC = ExactTC.getFixedValue();
+ if (TC == 0 || TC > TTI.getMinTripCountTailFoldingThreshold())
+ return false;
+
+ unsigned EstimatedWidth = estimateElementCount(
+ CurrentFactor.Width, Config.getVScaleForTuning());
+ if (TC != EstimatedWidth + 1)
+ return false;
+
+ InstructionCost VectorCost =
----------------
david-arm wrote:
Much of this code looks very similar to the code above on line 6138 and there is quite a lot of it to support a corner case. Can it be commonised? It would be good to simplify where possible.
https://github.com/llvm/llvm-project/pull/195823
More information about the llvm-commits
mailing list