[PATCH] D110623: [SLP] Avoid calculating expensive spill cost when it is not required

Dinar Temirbulatov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 28 06:04:46 PDT 2021


dtemirbulatov created this revision.
Herald added a subscriber: hiraditya.
dtemirbulatov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

https://reviews.llvm.org/D110623

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
@@ -736,6 +736,7 @@
     }
     MinBWs.clear();
     InstrElementSize.clear();
+    NoCallInst = true;
   }
 
   unsigned getTreeSize() const { return VectorizableTree.size(); }
@@ -2032,6 +2033,10 @@
   /// A list of blocks that we are going to CSE.
   SetVector<BasicBlock *> CSEBlocks;
 
+  /// The region of instruction that occupies VectorizableTree doesn't contain
+  /// any call instructions, indicating we don't need to calculate spill cost.
+  bool NoCallInst = true;
+
   /// Contains all scheduling relevant data for an instruction.
   /// A ScheduleData either represents a single instruction or a member of an
   /// instruction bundle (= a group of instructions which is combined into a
@@ -2181,8 +2186,8 @@
 
   /// Contains all scheduling data for a basic block.
   struct BlockScheduling {
-    BlockScheduling(BasicBlock *BB)
-        : BB(BB), ChunkSize(BB->size()), ChunkPos(ChunkSize) {}
+    BlockScheduling(BasicBlock *BB, BoUpSLP *R)
+        : BB(BB), R(R), ChunkSize(BB->size()), ChunkPos(ChunkSize) {}
 
     void clear() {
       ReadyInsts.clear();
@@ -2367,6 +2372,8 @@
 
     BasicBlock *BB;
 
+    BoUpSLP *R;
+
     /// Simple memory allocation for ScheduleData.
     std::vector<std::unique_ptr<ScheduleData[]>> ScheduleDataChunks;
 
@@ -3305,7 +3312,7 @@
 
   auto &BSRef = BlocksSchedules[BB];
   if (!BSRef)
-    BSRef = std::make_unique<BlockScheduling>(BB);
+    BSRef = std::make_unique<BlockScheduling>(BB, this);
 
   BlockScheduling &BS = *BSRef.get();
 
@@ -5165,7 +5172,9 @@
     }
   }
 
-  InstructionCost SpillCost = getSpillCost();
+  InstructionCost SpillCost = 0;
+  if (!NoCallInst)
+    SpillCost = getSpillCost();
   Cost += SpillCost + ExtractCost;
   for (int I = 0, E = FirstUsers.size(); I < E; ++I) {
     // For the very first element - simple shuffle of the source vector.
@@ -6781,6 +6790,8 @@
       }
       CurrentLoadStore = SD;
     }
+    if (isa<CallInst>(I))
+      R->NoCallInst = false;
   }
   if (NextLoadStore) {
     if (CurrentLoadStore)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110623.375547.patch
Type: text/x-patch
Size: 2244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210928/87496123/attachment.bin>


More information about the llvm-commits mailing list