[llvm] [SLP][REVEC] getScalarizationOverhead should not be used when ScalarTy is FixedVectorType. (PR #117536)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 10:26:28 PST 2024


================
@@ -9616,8 +9616,20 @@ void BoUpSLP::reorderGatherNode(TreeEntry &TE) {
     Cost += ::getShuffleCost(*TTI, TTI::SK_InsertSubvector, VecTy, {}, CostKind,
                              Idx, getWidenedType(ScalarTy, Sz));
   }
-  Cost += TTI->getScalarizationOverhead(VecTy, DemandedElts, /*Insert=*/true,
-                                        /*Extract=*/false, CostKind);
+  if (isa<FixedVectorType>(ScalarTy)) {
+    assert(SLPReVec && "Only supported by REVEC.");
+    // If ScalarTy is FixedVectorType, we should use CreateInsertVector instead
+    // of CreateInsertElement.
+    unsigned ScalarTyNumElements = getNumElements(ScalarTy);
+    for (unsigned I : seq<unsigned>(TE.Scalars.size()))
+      if (DemandedElts[I])
+        Cost += TTI->getShuffleCost(
+            TTI::SK_InsertSubvector, VecTy, std::nullopt, CostKind,
+            I * ScalarTyNumElements, cast<FixedVectorType>(ScalarTy));
----------------
alexey-bataev wrote:

```suggestion
  if (auto *FTy = dyn_cast<FixedVectorType>(ScalarTy)) {
    assert(SLPReVec && "Only supported by REVEC.");
    // If ScalarTy is FixedVectorType, we should use CreateInsertVector instead
    // of CreateInsertElement.
    unsigned ScalarTyNumElements = getNumElements(ScalarTy);
    for (unsigned I : seq<unsigned>(TE.Scalars.size()))
      if (DemandedElts[I])
        Cost += TTI->getShuffleCost(
            TTI::SK_InsertSubvector, VecTy, std::nullopt, CostKind,
            I * ScalarTyNumElements, FTy);
```


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


More information about the llvm-commits mailing list