[llvm] [SLP] Split blocking build-vector stores in scalar chains (PR #194970)

Yaxun Liu via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 07:33:17 PDT 2026


================
@@ -27302,20 +27240,137 @@ bool SLPVectorizerPass::vectorizeStores(
                         return A && (!B || A->getStride() < B->getStride());
                       });
 
+    auto TryVectorizeVectorLaneContext = [&](StoreChainContext &Context,
+                                             unsigned VF) {
+      ArrayRef<StoreLane> Lanes = Context.getOperands();
+      bool HasScalarLane = any_of(
+          Lanes, [](const StoreLane &Lane) { return !Lane.IsVectorLane; });
+      // Keep the initial support transactional: every lane must belong to a
+      // full output group, so no original vector store is partly replaced.
+      if (!Context.hasVectorLane() || !HasScalarLane || Lanes.size() % VF != 0)
+        return false;
+
+      // A vector store can cover lanes that land in several output groups. For
+      // example, p[3..6] may be replaced by new stores p[0..3] and p[4..7].
+      // Only erase the original stores after every affected group is
+      // profitable.
+      SmallVector<Instruction *> StoresToReplace;
+      SmallDenseSet<Value *> UserIgnoreList;
+      for (const StoreLane &Lane : Lanes) {
+        if (is_contained(StoresToReplace, Lane.Store))
+          continue;
+        StoresToReplace.push_back(Lane.Store);
+        UserIgnoreList.insert(Lane.Store);
+        if (!Lane.IsVectorLane)
+          continue;
+        SmallVector<Value *, 16> Elts;
+        SmallVector<Instruction *, 16> BuildVectorInsts;
+        if (!collectBuildVector(Lane.Store->getValueOperand(), Elts,
+                                BuildVectorInsts))
+          return false;
+        for (Instruction *I : BuildVectorInsts)
+          UserIgnoreList.insert(I);
+      }
----------------
yxsamliu wrote:

The separate pre-pass/trick is gone. The new path calls R.buildTree (LaneValues, UserIgnoreList) directly, so the value subtree for the lanes is built as regular Vectorize and NeedToGather TreeEntry nodes. The bulk of vectorization, including reorder, transformNodes, computeMinimumValueSizes and the cost trim, runs through the standard SLP tree machinery on those nodes. The final wider store is emitted at the end of the slice handler, similar to a horizontal reduction's final operation, because under this framing the old insertelement chain and stores are the store-reduction sink rather than normal lane-producing TreeEntry nodes themselves.

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


More information about the llvm-commits mailing list