[llvm] [SLP]Improve findReusedOrderedScalars and graph rotation. (PR #77523)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 13:26:09 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 036e48e2f5f890e1f9574cdb610e2336f12038a2 5de120ea76505a743c25860c28ab1832ef943a50 -- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 86b55c18e2..4765cef290 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3809,73 +3809,73 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE) {
       (GatherShuffles.empty() && IsBroadcastMask(ExtractMask)))
     return std::nullopt;
   SmallBitVector ShuffledSubMasks(NumParts);
-  auto TransformMaskToOrder =
-      [&](MutableArrayRef<unsigned> CurrentOrder, ArrayRef<int> Mask,
-          int PartSz, int NumParts, function_ref<unsigned(unsigned)> GetVF) {
-        for (int I : seq<int>(0, NumParts)) {
-          if (ShuffledSubMasks.test(I))
-            continue;
-          const int VF = GetVF(I);
-          if (VF == 0)
-            continue;
-          MutableArrayRef<unsigned> Slice = CurrentOrder.slice(I * PartSz, PartSz);
-          // Shuffle of at least 2 vectors - ignore.
-          if (any_of(Slice,[&](int I) {return I != NumScalars;})) {
-            std::fill(Slice.begin(), Slice.end(), NumScalars);
-            ShuffledSubMasks.set(I);
-            continue;
-          }
-          // Try to include as much elements from the mask as possible.
-          int FirstMin = INT_MAX;
-          int SecondVecFound = false;
-          for (int K : seq<int>(0, PartSz)) {
-            int Idx = Mask[I * PartSz + K];
-            if (Idx == PoisonMaskElem) {
-              Value *V = GatheredScalars[I * PartSz + K];
-              if (isConstant(V) && !isa<PoisonValue>(V)) {
-                SecondVecFound = true;
-                break;
-              }
-              continue;
-            }
-            if (Idx < VF) {
-              if (FirstMin > Idx)
-                FirstMin = Idx;
-            } else {
-              SecondVecFound = true;
-              break;
-            }
-          }
-          FirstMin = (FirstMin / PartSz) * PartSz;
-          // Shuffle of at least 2 vectors - ignore.
-          if (SecondVecFound) {
-            std::fill(Slice.begin(), Slice.end(), NumScalars);
-            ShuffledSubMasks.set(I);
-            continue;
-          }
-          for (int K : seq<int>(0, PartSz)) {
-            int Idx = Mask[I * PartSz + K];
-            if (Idx == PoisonMaskElem)
-              continue;
-            Idx -= FirstMin;
-            if (Idx >= PartSz) {
-              SecondVecFound = true;
-              break;
-            }
-            if (CurrentOrder[I * PartSz + Idx] >
-                    static_cast<unsigned>(I * PartSz + K) &&
-                CurrentOrder[I * PartSz + Idx] !=
-                    static_cast<unsigned>(I * PartSz + Idx))
-              CurrentOrder[I * PartSz + Idx] = I * PartSz + K;
-          }
-          // Shuffle of at least 2 vectors - ignore.
-          if (SecondVecFound) {
-            std::fill(Slice.begin(), Slice.end(), NumScalars);
-            ShuffledSubMasks.set(I);
-            continue;
+  auto TransformMaskToOrder = [&](MutableArrayRef<unsigned> CurrentOrder,
+                                  ArrayRef<int> Mask, int PartSz, int NumParts,
+                                  function_ref<unsigned(unsigned)> GetVF) {
+    for (int I : seq<int>(0, NumParts)) {
+      if (ShuffledSubMasks.test(I))
+        continue;
+      const int VF = GetVF(I);
+      if (VF == 0)
+        continue;
+      MutableArrayRef<unsigned> Slice = CurrentOrder.slice(I * PartSz, PartSz);
+      // Shuffle of at least 2 vectors - ignore.
+      if (any_of(Slice, [&](int I) { return I != NumScalars; })) {
+        std::fill(Slice.begin(), Slice.end(), NumScalars);
+        ShuffledSubMasks.set(I);
+        continue;
+      }
+      // Try to include as much elements from the mask as possible.
+      int FirstMin = INT_MAX;
+      int SecondVecFound = false;
+      for (int K : seq<int>(0, PartSz)) {
+        int Idx = Mask[I * PartSz + K];
+        if (Idx == PoisonMaskElem) {
+          Value *V = GatheredScalars[I * PartSz + K];
+          if (isConstant(V) && !isa<PoisonValue>(V)) {
+            SecondVecFound = true;
+            break;
           }
+          continue;
         }
-      };
+        if (Idx < VF) {
+          if (FirstMin > Idx)
+            FirstMin = Idx;
+        } else {
+          SecondVecFound = true;
+          break;
+        }
+      }
+      FirstMin = (FirstMin / PartSz) * PartSz;
+      // Shuffle of at least 2 vectors - ignore.
+      if (SecondVecFound) {
+        std::fill(Slice.begin(), Slice.end(), NumScalars);
+        ShuffledSubMasks.set(I);
+        continue;
+      }
+      for (int K : seq<int>(0, PartSz)) {
+        int Idx = Mask[I * PartSz + K];
+        if (Idx == PoisonMaskElem)
+          continue;
+        Idx -= FirstMin;
+        if (Idx >= PartSz) {
+          SecondVecFound = true;
+          break;
+        }
+        if (CurrentOrder[I * PartSz + Idx] >
+                static_cast<unsigned>(I * PartSz + K) &&
+            CurrentOrder[I * PartSz + Idx] !=
+                static_cast<unsigned>(I * PartSz + Idx))
+          CurrentOrder[I * PartSz + Idx] = I * PartSz + K;
+      }
+      // Shuffle of at least 2 vectors - ignore.
+      if (SecondVecFound) {
+        std::fill(Slice.begin(), Slice.end(), NumScalars);
+        ShuffledSubMasks.set(I);
+        continue;
+      }
+    }
+  };
   int PartSz = NumScalars / NumParts;
   if (!ExtractShuffles.empty())
     TransformMaskToOrder(
@@ -4705,7 +4705,7 @@ void BoUpSLP::reorderTopToBottom() {
       if (Cnt < Pair.second ||
           (Cnt == IdentityCnt && IdentityCnt == FilledIdentityCnt &&
            Cnt == Pair.second && !BestOrder.empty() &&
-             IsIdentityOrder(BestOrder))) {
+           IsIdentityOrder(BestOrder))) {
         combineOrders(Pair.first, BestOrder);
         BestOrder = Pair.first;
         Cnt = Pair.second;
@@ -9963,8 +9963,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
 SmallVector<std::optional<TargetTransformInfo::ShuffleKind>>
 BoUpSLP::isGatherShuffledEntry(
     const TreeEntry *TE, ArrayRef<Value *> VL, SmallVectorImpl<int> &Mask,
-    SmallVectorImpl<SmallVector<const TreeEntry *>> &Entries,
-    unsigned NumParts, bool ForOrder) {
+    SmallVectorImpl<SmallVector<const TreeEntry *>> &Entries, unsigned NumParts,
+    bool ForOrder) {
   assert(NumParts > 0 && NumParts < VL.size() &&
          "Expected positive number of registers.");
   Entries.clear();

``````````

</details>


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


More information about the llvm-commits mailing list