[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
================
@@ -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()));
----------------
mshockwave wrote:
> to simply doing I->getMask() == SpecificMask.
Please see my relevant review comment on this.
> 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?
The test for the equality of Mask and MaskContents is actually needed for the capture variant, namely `m_Shiffle`. The idea is that since `m_Shuffle` is supposed to capture the mask, in the unit test you want to make sure the mask you obtained matches the mask of the underlying SDNode.
https://github.com/llvm/llvm-project/pull/119592
More information about the llvm-commits
mailing list