[llvm] [SLP]Drop unprofitable splat gather subtrees (PR #221717)

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 19:00:45 PDT 2026


================
@@ -19635,7 +19369,32 @@ BoUpSLP::calculateTreeCostAndTrimNonProfitable(ArrayRef<Value *> VectorizedVals,
     // trimming of the subtree's own nodes would otherwise make it look
     // artificially cheap.
     KeepCost += std::get<1>(SubtreeCosts[TE->Idx]);
-    return KeepCost <= GetGatherInsertCost(ScalarTy, ValuesToInsert);
+    // The reusing gather nodes currently pay the broadcast cost; without
+    // the subtree they fall back to plain insertion sequences. Gather
+    // nodes already erased from NodesCosts are being deleted and do not
+    // count on either side.
+    CurrentGathersCost = 0;
+    for (const auto &[BVE, Values] : ValuesToInsert)
+      CurrentGathersCost += NodesCosts.lookup(BVE);
+    KeepCost += CurrentGathersCost;
+    // Re-cost the gather nodes with the subtree tentatively deleted.
+    DeletedNodes.insert(TE);
+    SmallVector<TreeEntry *> TempDeleted;
+    for (unsigned Idx : std::get<2>(SubtreeCosts[TE->Idx])) {
+      TreeEntry *Child = VectorizableTree[Idx].get();
+      if (DeletedNodes.insert(Child).second)
+        TempDeleted.push_back(Child);
+    }
----------------
bababuck wrote:

Thanks for the follow up :)

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


More information about the llvm-commits mailing list