[llvm] [SLP][REVEC] Make ShuffleCostEstimator and ShuffleInstructionBuilder can vectorize vector instructions. (PR #99606)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 07:41:40 PDT 2024


================
@@ -253,6 +253,21 @@ static FixedVectorType *getWidenedType(Type *ScalarTy, unsigned VF) {
                               VF * getNumElements(ScalarTy));
 }
 
+static void transformScalarShuffleIndiciesToVector(unsigned VecTyNumElements,
+                                                   SmallVectorImpl<int> &Mask) {
+  // The ShuffleBuilder implementation use shufflevector to splat an "element".
+  // But the element have different meaning for SLP (scalar) and REVEC
+  // (vector). We need to expand Mask into masks which shufflevector can use
+  // directly.
+  SmallVector<int> NewMask(Mask.size() * VecTyNumElements);
+  for (size_t I = 0, E = Mask.size(); I != E; ++I)
+    for (unsigned J = 0; J != VecTyNumElements; ++J)
+      NewMask[I * VecTyNumElements + J] = Mask[I] == PoisonMaskElem
+                                              ? PoisonMaskElem
+                                              : Mask[I] * VecTyNumElements + J;
----------------
alexey-bataev wrote:

```suggestion
    for (auto [I, MaskV] : enumerate(MutableArrayRef(NewMask).slice(I * VecTyNumElements, VecTyNumElements)))
      MaskV = Mask[I] == PoisonMaskElem
                                              ? PoisonMaskElem
                                              : Mask[I] * VecTyNumElements + J;


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


More information about the llvm-commits mailing list