[PATCH] D99745: [SLP] Special case SK_PermuteSingleSrc extract cost estimate (NFCI).

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 1 10:00:13 PDT 2021


fhahn created this revision.
fhahn added reviewers: ABataev, RKSimon, spatel, vdmitrie, dtemirbulatov.
Herald added a subscriber: hiraditya.
fhahn requested review of this revision.
Herald added a project: LLVM.

Preparation for more fine-grained cost estimates for extracts that form
a SK_PermuteSingleSrc pattern.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99745

Files:
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp


Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3488,8 +3488,19 @@
       Optional<TargetTransformInfo::ShuffleKind> ShuffleKind =
           isShuffle(VL, Mask);
       if (ShuffleKind.hasValue()) {
-        InstructionCost Cost =
-            TTI->getShuffleCost(ShuffleKind.getValue(), VecTy, Mask);
+        InstructionCost Cost = 0;
+
+        if (*ShuffleKind != TargetTransformInfo::SK_PermuteSingleSrc)
+          Cost += TTI->getShuffleCost(ShuffleKind.getValue(), VecTy, Mask);
+
+        unsigned NumOfParts = TTI->getNumberOfParts(VecTy);
+        // Compute the number of number of elements per vector register for
+        // VecTy. If that is not possible, because the number of parts for VecTy
+        // is unknown, use the maximum value for unsigned.
+        unsigned EltsPerVector =
+            NumOfParts ? VecTy->getNumElements() / NumOfParts : -1;
+        unsigned Idx = 0;
+
         for (auto *V : VL) {
           // If all users of instruction are going to be vectorized and this
           // instruction itself is not going to be vectorized, consider this
@@ -3502,6 +3513,26 @@
             Cost -= TTI->getVectorInstrCost(Instruction::ExtractElement, VecTy,
                                             IO->getZExtValue());
           }
+          if (*ShuffleKind == TargetTransformInfo::SK_PermuteSingleSrc) {
+            if ((Idx > 0 && (Idx + 1) % EltsPerVector == 0) ||
+                Idx + 1 == VL.size()) {
+              SmallVector<int> Mask;
+              unsigned StartIdx =
+                  Idx - std::min(EltsPerVector, VecTy->getNumElements()) + 1;
+              Optional<TargetTransformInfo::ShuffleKind> ShuffleKind =
+                  isShuffle(
+                      {&VL[StartIdx],
+                       std::min(EltsPerVector, unsigned(VL.size() - StartIdx))},
+                      Mask);
+              Cost += TTI->getShuffleCost(
+                  ShuffleKind.getValue(),
+                  FixedVectorType::get(
+                      VecTy->getElementType(),
+                      std::min(EltsPerVector, VecTy->getNumElements())),
+                  Mask);
+            }
+          }
+          ++Idx;
         }
         return ReuseShuffleCost + Cost;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99745.334736.patch
Type: text/x-patch
Size: 2422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210401/ace00646/attachment.bin>


More information about the llvm-commits mailing list