[llvm] [SLP] More accurately cost RISCV scalar splats (PR #213104)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 03:40:37 PDT 2026


================
@@ -22561,10 +22610,32 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Type *ScalarTy,
     // Gather unique scalars and all constants.
     SmallVector<int> ReuseMask(GatheredScalars.size(), PoisonMaskElem);
     TryPackScalars(GatheredScalars, ReuseMask, /*IsRootPoison=*/true);
-    Value *BV = ShuffleBuilder.gather(GatheredScalars, ReuseMask.size());
-    ShuffleBuilder.add(BV, ReuseMask);
+    auto GatherUserOps = [&](SmallVectorImpl<TTI::BuildVectorUseOp> &UserOps) {
+      UserOps.clear();
+      if (NeedFreeze)
+        return false;
+      for (const auto &TE : VectorizableTree) {
+        if (DeletedNodes.contains(TE.get()))
+          continue;
+        if (!(TE->isGather() || TransformedToGatherNodes.contains(TE.get())) ||
+            !E->isSame(TE->Scalars))
+          continue;
+        auto *UserTE = TE->UserTreeIndex.UserTE;
+        if (!UserTE || !UserTE->hasState() || UserTE->isAltShuffle() ||
+            TransformedToGatherNodes.contains(UserTE))
+          return false;
+        UserOps.emplace_back(UserTE->getOpcode(), TE->UserTreeIndex.EdgeIdx);
+      }
+      assert(UserOps.size() && "Ought to at least match with current entry");
+      return true;
+    };
+    TargetTransformInfo::VectorInstrContext ContextHint =
+        TTI->getBuildVectorContextHint(ReuseMask, E->Scalars, GatherUserOps);
----------------
alexey-bataev wrote:

```suggestion
    ContextHint =
        TTI->getBuildVectorContextHint(ReuseMask, E->Scalars, GatherUserOps);
    }
```
to calculate only in cost estimation and skip for codegen

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


More information about the llvm-commits mailing list