[llvm] [SLPVectorizer] Use accurate cost for external users of resize shuffles (PR #137419)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 06:47:07 PDT 2025


================
@@ -14802,7 +14803,39 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals,
                  << " for final shuffle of insertelement external users.\n";
           TE->dump(); dbgs() << "SLP: Current total cost = " << Cost << "\n");
       Cost += C;
-      return std::make_pair(TE, true);
+
+      bool HasLargeIndex =
+          any_of(Mask, [VF](int Idx) { return Idx >= static_cast<int>(VF); });
+
+      // If the resize source is just an identity vector, then will produce an
+      // insert subvector shufflevector
+      bool NeedsResizeExtract = true;
+      if ((VecVF < VF) && !HasLargeIndex) {
+        NeedsResizeExtract = false;
+        SmallVector<int> ResizeMask(VF, PoisonMaskElem);
+        for (unsigned I = 0; I < VF; ++I) {
+          if (Mask[I] != PoisonMaskElem) {
+            assert((size_t)Mask[I] < ResizeMask.size());
+            ResizeMask[Mask[I]] = Mask[I];
+          }
+        }
+
+        unsigned MinVF = std::min(VF, VecVF);
+        // Check if our mask is a a padded identity mask with non poision
----------------
alexey-bataev wrote:

poison

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


More information about the llvm-commits mailing list