[llvm] [SLP]Add cost estimation for gather node reshuffling (PR #115201)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 04:35:15 PST 2024


================
@@ -982,17 +982,32 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
       return Kind;
     int NumSrcElts = Ty->getElementCount().getKnownMinValue();
     switch (Kind) {
-    case TTI::SK_PermuteSingleSrc:
+    case TTI::SK_PermuteSingleSrc: {
       if (ShuffleVectorInst::isReverseMask(Mask, NumSrcElts))
         return TTI::SK_Reverse;
       if (ShuffleVectorInst::isZeroEltSplatMask(Mask, NumSrcElts))
         return TTI::SK_Broadcast;
+      // Check that the broadcast index meets at least twice.
+      bool IsCompared = false;
+      if (int SplatIdx = PoisonMaskElem;
+          all_of(enumerate(Mask), [&](const auto &P) {
+            if (P.value() == PoisonMaskElem)
+              return P.index() != Mask.size() - 1 || IsCompared;
+            if (SplatIdx == PoisonMaskElem) {
+              SplatIdx = P.value();
+              return P.index() != Mask.size() - 1;
+            }
+            IsCompared = true;
+            return SplatIdx == P.value();
+          }))
+        return TTI::SK_Broadcast;
----------------
alexey-bataev wrote:

Done

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


More information about the llvm-commits mailing list