[PATCH] D63948: [SLP] Limit compilation time of look-ahead operand reordering heuristic.

Vasileios Porpodas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 11:43:34 PDT 2019


vporpo created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

This is a fix for the compilation time increase caused by D60897 <https://reviews.llvm.org/D60897>. It caps the exploration performed by the look-ahead heuristic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63948

Files:
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp


Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -817,6 +817,7 @@
         // and RHS as base and Idx as the offset.
         int Ln = std::min(LHS.second, RHS.second) + Idx;
         assert(Ln >= 0 && "Bad lane calculation");
+        unsigned UsersBudget = 4;
         for (User *U : V->users()) {
           if (const TreeEntry *UserTE = R.getTreeEntry(U)) {
             // The user is in the VectorizableTree. Check if we need to insert.
@@ -838,6 +839,9 @@
               Cost += ExternalUseCost;
             }
           }
+          // Limit the number of visited uses to cap compilation time.
+          if (--UsersBudget == 0)
+            break;
         }
       }
       return Cost;
@@ -898,7 +902,10 @@
 
       // Recursion towards the operands of I1 and I2. We are trying all possbile
       // operand pairs, and keeping track of the best score.
-      for (unsigned OpIdx1 = 0, NumOperands1 = I1->getNumOperands();
+      // Limit the number of operands to visit to reduce compilation time.
+      unsigned OperandsBudget = 2;
+      for (unsigned OpIdx1 = 0, NumOperands1 = std::max(I1->getNumOperands(),
+                                                        OperandsBudget);
            OpIdx1 != NumOperands1; ++OpIdx1) {
         // Try to pair op1I with the best operand of I2.
         int MaxTmpScore = 0;
@@ -907,7 +914,7 @@
         // If I2 is commutative try all combinations.
         unsigned FromIdx = isCommutative(I2) ? 0 : OpIdx1;
         unsigned ToIdx = isCommutative(I2)
-                             ? I2->getNumOperands()
+                             ? std::max(I2->getNumOperands(), OperandsBudget)
                              : std::min(I2->getNumOperands(), OpIdx1 + 1);
         assert(FromIdx <= ToIdx && "Bad index");
         for (unsigned OpIdx2 = FromIdx; OpIdx2 != ToIdx; ++OpIdx2) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63948.207118.patch
Type: text/x-patch
Size: 2024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190628/1ffd67d2/attachment.bin>


More information about the llvm-commits mailing list