diff options
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp index da56cb2..da0aee6 100644 --- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -533,6 +533,67 @@ TEST_F(AArch64GISelMITest, MatchSpecificConstant) { EXPECT_FALSE(mi_match(MIBAdd.getReg(1), *MRI, m_SpecificICst(42))); } +TEST_F(AArch64GISelMITest, MatchSpecificConstantSplat) { + setUp(); + if (!TM) + return; + + LLT s64 = LLT::scalar(64); + LLT v4s64 = LLT::fixed_vector(4, s64); + + MachineInstrBuilder FortyTwoSplat = + B.buildSplatVector(v4s64, B.buildConstant(s64, 42)); + MachineInstrBuilder FortyTwo = B.buildConstant(s64, 42); + + EXPECT_TRUE(mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstSplat(42))); + EXPECT_FALSE( + mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstSplat(43))); + EXPECT_FALSE(mi_match(FortyTwo.getReg(0), *MRI, m_SpecificICstSplat(42))); + + MachineInstrBuilder NonConstantSplat = + B.buildBuildVector(v4s64, {Copies[0], Copies[0], Copies[0], Copies[0]}); + + MachineInstrBuilder AddSplat = + B.buildAdd(v4s64, NonConstantSplat, FortyTwoSplat); + EXPECT_TRUE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstSplat(42))); + EXPECT_FALSE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstSplat(43))); + EXPECT_FALSE(mi_match(AddSplat.getReg(1), *MRI, m_SpecificICstSplat(42))); + + MachineInstrBuilder Add = B.buildAdd(s64, Copies[0], FortyTwo); + EXPECT_FALSE(mi_match(Add.getReg(2), *MRI, m_SpecificICstSplat(42))); +} + +TEST_F(AArch64GISelMITest, MatchSpecificConstantOrSplat) { + setUp(); + if (!TM) + return; + + LLT s64 = LLT::scalar(64); + LLT v4s64 = LLT::fixed_vector(4, s64); + + MachineInstrBuilder FortyTwoSplat = + B.buildSplatVector(v4s64, B.buildConstant(s64, 42)); + MachineInstrBuilder FortyTwo = B.buildConstant(s64, 42); + + EXPECT_TRUE( + mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstOrSplat(42))); + EXPECT_FALSE( + mi_match(FortyTwoSplat.getReg(0), *MRI, m_SpecificICstOrSplat(43))); + EXPECT_TRUE(mi_match(FortyTwo.getReg(0), *MRI, m_SpecificICstOrSplat(42))); + + MachineInstrBuilder NonConstantSplat = + B.buildBuildVector(v4s64, {Copies[0], Copies[0], Copies[0], Copies[0]}); + + MachineInstrBuilder AddSplat = + B.buildAdd(v4s64, NonConstantSplat, FortyTwoSplat); + EXPECT_TRUE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstOrSplat(42))); + EXPECT_FALSE(mi_match(AddSplat.getReg(2), *MRI, m_SpecificICstOrSplat(43))); + EXPECT_FALSE(mi_match(AddSplat.getReg(1), *MRI, m_SpecificICstOrSplat(42))); + + MachineInstrBuilder Add = B.buildAdd(s64, Copies[0], FortyTwo); + EXPECT_TRUE(mi_match(Add.getReg(2), *MRI, m_SpecificICstOrSplat(42))); +} + TEST_F(AArch64GISelMITest, MatchZeroInt) { setUp(); if (!TM) |