[llvm] [SLP][REVEC] Support more mask pattern usage in shufflevector. (PR #106212)

Han-Kuan Chen via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 04:02:40 PDT 2024


================
@@ -318,12 +317,11 @@ static unsigned getShufflevectorNumGroups(ArrayRef<Value *> VL) {
           int Index;
           if (!SV->isExtractSubvectorMask(Index))
             return false;
-          for (int I : seq<int>(Index, Index + SV->getShuffleMask().size()))
-            ExtractionIndex.push_back(I);
+          UsedIndex.set(Index, Index + SV->getShuffleMask().size());
           return true;
         }))
       return 0;
-    if (!is_sorted(ExtractionIndex))
+    if (!UsedIndex.all())
----------------
HanKuanChen wrote:

Cannot. We had a `getShufflevectorNumGroups` in `getScalarsVectorizationState`. If `getShufflevectorNumGroups` returns 0, then `buildTree_rec` will stop (a `TreeEntry::NeedToGather` will return).
`getShufflevectorNumGroups` use
```
    SmallVector<int> ExtractionIndex(SVNumElements);
    if (!all_of(Group, [&](Value *V) {
          auto *SV = cast<ShuffleVectorInst>(V);
          // From the same source.
          if (SV->getOperand(0) != Src)
            return false;
          int Index;
          if (!SV->isExtractSubvectorMask(Index))
            return false;
          for (int I : seq<int>(Index, Index + SV->getShuffleMask().size()))
            ExtractionIndex.push_back(I);
          return true;
        }))
      return 0;
    if (!is_sorted(ExtractionIndex))
      return 0;
```
to make sure each elements will be accessed.

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


More information about the llvm-commits mailing list