[llvm] [LoopVectorize] Improve Vectorization of Low Trip Count Loops (PR #195823)
Jack Styles via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 07:56:57 PDT 2026
================
@@ -6092,6 +6152,33 @@ LoopVectorizationPlanner::computeBestVF() {
assert((FirstPlan.hasScalarVFOnly() || hasPlanWithVF(UserVF) ||
FirstPlan.isOuterLoop()) &&
"must have a single scalar VF, UserVF or an outer loop");
+ bool ForceVectorization =
+ Hints.getForce() == LoopVectorizeHints::FK_Enabled;
+ if (!FirstPlan.hasScalarVFOnly() && !FirstPlan.isOuterLoop() &&
+ hasPlanWithVF(UserVF) && UserVF.isVector() && !ForceVectorization) {
+ ElementCount ExactTC = getSmallConstantTripCount(PSE.getSE(), OrigLoop);
+ if (FirstPlan.hasScalarTail() && ExactTC.isFixed() && UserVF.isFixed()) {
+ unsigned TC = ExactTC.getFixedValue();
+ unsigned EstimatedWidth =
+ estimateElementCount(UserVF, Config.getVScaleForTuning());
+ if (TC != 0 && TC <= TTI.getMinTripCountTailFoldingThreshold() &&
+ TC == EstimatedWidth + 1) {
+ ElementCount ScalarVF = ElementCount::getFixed(1);
+ InstructionCost ScalarCost = CM.expectedCost(ScalarVF);
+ LLVM_DEBUG(dbgs()
+ << "LV: Scalar loop costs: " << ScalarCost << ".\n");
+
+ InstructionCost Cost = cost(FirstPlan, UserVF, /*RU=*/nullptr);
+ VectorizationFactor UserFactor(UserVF, Cost, ScalarCost);
+ VectorizationFactor ScalarFactor(ScalarVF, ScalarCost, ScalarCost);
+ if (IsUnprofitableOneScalarTail(UserFactor, FirstPlan.hasScalarTail(),
----------------
Stylie777 wrote:
Agreed, Removed
https://github.com/llvm/llvm-project/pull/195823
More information about the llvm-commits
mailing list