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

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 10:06:23 PST 2024


================
@@ -540,6 +540,48 @@ struct BinaryOpc_match {
   }
 };
 
+/// Matching while capturing mask
+template <typename T0, typename T1> struct SDShuffle_match {
+  T0 Op1;
+  T1 Op2;
+
+  ArrayRef<int> &CapturedMask;
+
+  // capturing mask
+  SDShuffle_match(const T0 &Op1, const T1 &Op2, ArrayRef<int> &MaskRef)
+      : Op1(Op1), Op2(Op2), CapturedMask(MaskRef) {}
+
+  template <typename MatchContext>
+  bool match(const MatchContext &Ctx, SDValue N) {
+    if (auto *I = dyn_cast<ShuffleVectorSDNode>(N)) {
+      CapturedMask = I->getMask();
----------------
mshockwave wrote:

Do you want to capture the mask only when the sub-patterns match?

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


More information about the llvm-commits mailing list