[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
Sat Dec 14 16:00:52 PST 2024
================
@@ -540,6 +540,45 @@ struct BinaryOpc_match {
}
};
+/// Matching while capturing mask
+template <typename T0, typename T1> struct SDShuffle_match {
+ T0 Op1;
+ T1 Op2;
+
+ const ArrayRef<int> *MaskRef;
+
+ // capturing mask
+ SDShuffle_match(const T0 &Op1, const T1 &Op2, const ArrayRef<int> &MaskRef)
+ : Op1(Op1), Op2(Op2), MaskRef(&MaskRef) {}
+
+ 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));
+ }
+ return false;
+ }
+};
+
+/// Matching against a specific match
+template <typename T0, typename T1> struct SDShuffle_maskMatch {
+ T0 Op1;
+ T1 Op2;
+ ArrayRef<int> SpecificMask;
+
+ SDShuffle_maskMatch(const T0 &Op1, const T1 &Op2, const ArrayRef<int> Mask)
+ : Op1(Op1), Op2(Op2), SpecificMask(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)) && I->getMask() == SpecificMask;
----------------
mshockwave wrote:
> I->getMask() == SpecificMask
I don't think this is the right way to compare mask. As I mentioned before, `ArrayRef` should be treated as a pointer. So what you do here is essentially comparing two pointers, which is wrong. You probably want to do element-wise comparison.
https://github.com/llvm/llvm-project/pull/119592
More information about the llvm-commits
mailing list