[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
Thu Dec 12 12:45:54 PST 2024
================
@@ -540,6 +549,25 @@ struct BinaryOpc_match {
}
};
+/// Matches shuffle.
+template <typename T0, typename T1> struct SDShuffle_match {
+ T0 Op1;
+ T1 Op2;
+ ArrayRef<int> Mask;
+
+ SDShuffle_match(const T0 &Op1, const T1 &Op2, const ArrayRef<int> &Mask)
----------------
mshockwave wrote:
First of all, ArrayRef tries to model a reference and it's more like a pointer than an object, so you should pass it by value according to what you try to do here.
Second, I would like to invite you to step back a little bit and think about what you want to achieve here first -- there are two possible scenarios where you need `m_Shuffle` w.r.t masks: either you want to _obtain_ the mask from a shuffle, or you want to match against a shuffle with a _specific_ mask. In the first scenario, you'll store a reference to the output mask variable inside `SDShuffle_match` and write the mask value into it upon matching the shuffle. What you do here is more like the second scenraio, where the user provide a mask and `SDPattern_match` matches a shuffle with that mask.
However, it seems like your unit test is expecting the _first_ scenario (which is also what you did in the previous version of the patch). Therefore, I think this is wrong.
I'll say you can implement either one of the two scenarios in this patch, or implement both with two different matching functions / classes. For instance, `m_Shuffle` for the first scenario, and something like `m_ShuffleSpecificMask` for the second scenario.
https://github.com/llvm/llvm-project/pull/119592
More information about the llvm-commits
mailing list