[llvm] [LoopVectorizer] Prune VFs based on plan register pressure (PR #132190)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 08:48:10 PDT 2025


================
@@ -4550,11 +4535,22 @@ VectorizationFactor LoopVectorizationPlanner::selectVectorizationFactor() {
   }
 
   for (auto &P : VPlans) {
-    for (ElementCount VF : P->vectorFactors()) {
+    ArrayRef<ElementCount> VFs(P->vectorFactors().begin(),
+                               P->vectorFactors().end());
+    auto RUs = ::calculateRegisterUsage(*P, VFs, TTI, CM.ValuesToIgnore);
+    for (auto [VF, RU] : zip_equal(VFs, RUs)) {
       // The cost for scalar VF=1 is already calculated, so ignore it.
       if (VF.isScalar())
         continue;
 
+      /// Don't consider the VF if it exceeds the number of registers for the
+      /// target.
+      const auto &MLU = RU.MaxLocalUsers;
+      if (any_of(MLU, [&](decltype(MLU.front()) &LU) {
+            return LU.second > TTI.getNumberOfRegisters(LU.first);
+          }))
----------------
SamTebbs33 wrote:

Done!

https://github.com/llvm/llvm-project/pull/132190


More information about the llvm-commits mailing list