[llvm] Add SD matchers and unit test coverage for ISD::VECTOR_SHUFFLE (PR #119592)

Aidan Goldfarb via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 30 11:28:34 PST 2024


================
@@ -547,6 +547,39 @@ struct BinaryOpc_match {
   }
 };
 
+/// Matching while capturing mask
+template <typename T0, typename T1, typename T2> struct SDShuffle_match {
+  T0 Op1;
+  T1 Op2;
+  T2 Mask;
+
+  SDShuffle_match(const T0 &Op1, const T1 &Op2, const T2 &Mask)
+      : Op1(Op1), Op2(Op2), Mask(Mask) {}
+
+  template <typename MatchContext>
+  bool match(const MatchContext &Ctx, SDValue N) {
+    if (auto *I = dyn_cast<ShuffleVectorSDNode>(N)) {
+      return Op1.match(Ctx, I->getOperand(0)) &&
+             Op2.match(Ctx, I->getOperand(1)) && Mask.match(I->getMask());
+    }
+    return false;
+  }
+};
+struct m_Mask {
+  ArrayRef<int> MaskRef;
----------------
AidanGoldfarb wrote:

Thank you for the help. My most recent commit incorporates these changes. I believe my test logic is correct.

Uninitialzed masks:
```
  const std::array<int, 4> MaskData = {2, 0, 3, 1};      //used to construct vectorshuffle with `DAG->getVectorShuffle()` 
  const std::array<int, 4> OtherMaskData = {1, 2, 3, 4};
  ArrayRef<int> Mask;                                    //captured with m_mask in test
```

however to m_SpecificMask should we be passing `MaskData` or `Mask` by value for a comparison?

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


More information about the llvm-commits mailing list