[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
Sat Dec 14 10:28:02 PST 2024


================
@@ -119,6 +119,26 @@ TEST_F(SelectionDAGPatternMatchTest, matchValueType) {
   EXPECT_FALSE(sd_match(Op2, m_ScalableVectorVT()));
 }
 
+TEST_F(SelectionDAGPatternMatchTest, matchVecShuffle) {
+  SDLoc DL;
+  auto Int32VT = EVT::getIntegerVT(Context, 32);
+  auto VInt32VT = EVT::getVectorVT(Context, Int32VT, 4);
+  SmallVector<int, 4> MaskData = {2, 0, 3, 1};
+  ArrayRef<int> Mask;
+
+  SDValue V0 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 1, VInt32VT);
+  SDValue V1 = DAG->getCopyFromReg(DAG->getEntryNode(), DL, 2, VInt32VT);
+  SDValue VecShuffleWithMask_0 =
+      DAG->getVectorShuffle(VInt32VT, DL, V0, V1, MaskData);
+
+  using namespace SDPatternMatch;
+  EXPECT_TRUE(
+      sd_match(VecShuffleWithMask_0, m_Shuffle(m_Value(V0), m_Value(V1))));
+  EXPECT_TRUE(sd_match(VecShuffleWithMask_0,
+                       m_Shuffle(m_Value(V0), m_Value(V1), Mask)));
+  EXPECT_TRUE(std::equal(Mask.begin(), Mask.end(), MaskData.begin()));
----------------
AidanGoldfarb wrote:

I resorted, in the refactored version, to simply doing `I->getMask() == SpecificMask`.  As `m_Mask` is no longer used, I believed the test for the equality of `Mask` and `MaskContents` after the call to `m_Mask` was no longer needed. The test for contents only matters in the `m_ShuffleSpecificMask` case?

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


More information about the llvm-commits mailing list