diff options
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp index c6a7f8e..f95b19f 100644 --- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -426,6 +426,17 @@ TEST_F(AArch64GISelMITest, MatchZeroInt) { EXPECT_FALSE(mi_match(FortyTwo.getReg(0), *MRI, m_ZeroInt())); } +TEST_F(AArch64GISelMITest, MatchAllOnesInt) { + setUp(); + if (!TM) + return; + auto AllOnes = B.buildConstant(LLT::scalar(64), -1); + EXPECT_TRUE(mi_match(AllOnes.getReg(0), *MRI, m_AllOnesInt())); + + auto FortyTwo = B.buildConstant(LLT::scalar(64), 42); + EXPECT_FALSE(mi_match(FortyTwo.getReg(0), *MRI, m_AllOnesInt())); +} + TEST_F(AArch64GISelMITest, MatchNeg) { setUp(); if (!TM) @@ -457,6 +468,39 @@ TEST_F(AArch64GISelMITest, MatchNeg) { EXPECT_TRUE(mi_match(AddInst.getReg(2), *MRI, m_Neg(m_Reg(NegatedReg)))); EXPECT_EQ(NegatedReg, Copies[0]); } + +TEST_F(AArch64GISelMITest, MatchNot) { + setUp(); + if (!TM) + return; + + LLT s64 = LLT::scalar(64); + auto AllOnes = B.buildConstant(LLT::scalar(64), -1); + auto NotInst1 = B.buildXor(s64, Copies[0], AllOnes); + Register NotReg; + + // Match: G_XOR %NotReg, -1 + EXPECT_TRUE(mi_match(NotInst1.getReg(0), *MRI, m_Not(m_Reg(NotReg)))); + EXPECT_EQ(NotReg, Copies[0]); + + // Match: G_XOR -1, %NotReg + auto NotInst2 = B.buildXor(s64, AllOnes, Copies[1]); + EXPECT_TRUE(mi_match(NotInst2.getReg(0), *MRI, m_Not(m_Reg(NotReg)))); + EXPECT_EQ(NotReg, Copies[1]); + + // Don't match: G_XOR %NotReg, 42 + auto FortyTwo = B.buildConstant(LLT::scalar(64), 42); + auto WrongCst = B.buildXor(s64, Copies[0], FortyTwo); + EXPECT_FALSE(mi_match(WrongCst.getReg(0), *MRI, m_Not(m_Reg(NotReg)))); + + // Complex testcase. + // %xor = G_XOR %NotReg, -1 + // %add = G_ADD %x, %xor + auto AddInst = B.buildAdd(s64, Copies[1], NotInst1); + NotReg = Register(); + EXPECT_TRUE(mi_match(AddInst.getReg(2), *MRI, m_Not(m_Reg(NotReg)))); + EXPECT_EQ(NotReg, Copies[0]); +} } // namespace int main(int argc, char **argv) { |