[llvm] 7024cec - [LV] Collect profitable VFs in ::getBestVF. (NFCI)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 11 06:46:14 PDT 2024


Author: Florian Hahn
Date: 2024-08-11T14:45:54+01:00
New Revision: 7024cecf03e6b5c1fd0fe1292ed18c7b808396f7

URL: https://github.com/llvm/llvm-project/commit/7024cecf03e6b5c1fd0fe1292ed18c7b808396f7
DIFF: https://github.com/llvm/llvm-project/commit/7024cecf03e6b5c1fd0fe1292ed18c7b808396f7.diff

LOG: [LV] Collect profitable VFs in ::getBestVF. (NFCI)

Move collectig profitable VFs to ::getBestVF, in preparation for
retiring selectVectorizationFactor.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index ca20bc3ada799..f627130053932 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -365,8 +365,9 @@ class LoopVectorizationPlanner {
   /// Return the best VPlan for \p VF.
   VPlan &getBestPlanFor(ElementCount VF) const;
 
-  /// Return the most profitable vectorization factor.
-  ElementCount getBestVF() const;
+  /// Return the most profitable vectorization factor. Also collect all
+  /// profitable VFs in ProfitableVFs.
+  ElementCount getBestVF();
 
   /// Generate the IR code for the vectorized loop captured in VPlan \p BestPlan
   /// according to the best selected \p VF and  \p UF.

diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 3852967a676aa..180eb43bb7181 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4606,10 +4606,6 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
         continue;
       }
 
-      // If profitable add it to ProfitableVF list.
-      if (isMoreProfitable(Candidate, ScalarCost))
-        ProfitableVFs.push_back(Candidate);
-
       if (isMoreProfitable(Candidate, ChosenFactor))
         ChosenFactor = Candidate;
     }
@@ -7200,7 +7196,7 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
   return Cost;
 }
 
-ElementCount LoopVectorizationPlanner::getBestVF() const {
+ElementCount LoopVectorizationPlanner::getBestVF() {
   // If there is a single VPlan with a single VF, return it directly.
   VPlan &FirstPlan = *VPlans[0];
   if (VPlans.size() == 1 && size(FirstPlan.vectorFactors()) == 1)
@@ -7212,7 +7208,8 @@ ElementCount LoopVectorizationPlanner::getBestVF() const {
 
   // TODO: Compute scalar cost using VPlan-based cost model.
   InstructionCost ScalarCost = CM.expectedCost(ScalarVF);
-  VectorizationFactor BestFactor(ScalarVF, ScalarCost, ScalarCost);
+  VectorizationFactor ScalarFactor(ScalarVF, ScalarCost, ScalarCost);
+  VectorizationFactor BestFactor = ScalarFactor;
 
   bool ForceVectorization = Hints.getForce() == LoopVectorizeHints::FK_Enabled;
   if (ForceVectorization) {
@@ -7238,6 +7235,10 @@ ElementCount LoopVectorizationPlanner::getBestVF() const {
       VectorizationFactor CurrentFactor(VF, Cost, ScalarCost);
       if (isMoreProfitable(CurrentFactor, BestFactor))
         BestFactor = CurrentFactor;
+
+      // If profitable add it to ProfitableVF list.
+      if (isMoreProfitable(CurrentFactor, ScalarFactor))
+        ProfitableVFs.push_back(CurrentFactor);
     }
   }
   return BestFactor.Width;


        


More information about the llvm-commits mailing list