[llvm] 2318491 - [SLP][NFC]Do the analysis first and then actual codegen, NFC

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 08:13:03 PDT 2025


Author: Alexey Bataev
Date: 2025-05-20T08:12:53-07:00
New Revision: 2318491432f7afb8f98713a2e43c685088cc729e

URL: https://github.com/llvm/llvm-project/commit/2318491432f7afb8f98713a2e43c685088cc729e
DIFF: https://github.com/llvm/llvm-project/commit/2318491432f7afb8f98713a2e43c685088cc729e.diff

LOG: [SLP][NFC]Do the analysis first and then actual codegen, NFC

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a8b28dd08a416..7df9ab039d887 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -18519,7 +18519,8 @@ Value *BoUpSLP::vectorizeTree(
   else
     Builder.SetInsertPoint(&F->getEntryBlock(), F->getEntryBlock().begin());
 
- // Vectorize gather operands of the nodes with the external uses only.
+  // Vectorize gather operands of the nodes with the external uses only.
+  SmallVector<std::pair<TreeEntry *, Instruction *>> GatherEntries;
   for (const std::unique_ptr<TreeEntry> &TE : VectorizableTree) {
     if (TE->isGather() && !TE->VectorizedValue && TE->UserTreeIndex.UserTE &&
         TE->UserTreeIndex.UserTE->hasState() &&
@@ -18530,11 +18531,14 @@ Value *BoUpSLP::vectorizeTree(
                [](Value *V) { return isUsedOutsideBlock(V); })) {
       Instruction &LastInst =
           getLastInstructionInBundle(TE->UserTreeIndex.UserTE);
-      Builder.SetInsertPoint(&LastInst);
-      Builder.SetCurrentDebugLocation(LastInst.getDebugLoc());
-      (void)vectorizeTree(TE.get());
+      GatherEntries.emplace_back(TE.get(), &LastInst);
     }
   }
+  for (auto &Entry : GatherEntries) {
+    Builder.SetInsertPoint(Entry.second);
+    Builder.SetCurrentDebugLocation(Entry.second->getDebugLoc());
+    (void)vectorizeTree(Entry.first);
+  }
   // Emit gathered loads first to emit better code for the users of those
   // gathered loads.
   for (const std::unique_ptr<TreeEntry> &TE : VectorizableTree) {


        


More information about the llvm-commits mailing list