diff options
author | Petar Avramovic <Petar.Avramovic@amd.com> | 2021-04-27 11:08:16 +0200 |
---|---|---|
committer | Petar Avramovic <Petar.Avramovic@amd.com> | 2021-04-27 11:08:16 +0200 |
commit | 39662abf720fc195b549246f32719d313f05a67f (patch) | |
tree | 9957737b0aa0f3c4201fba6d5acd03a11e43fac2 /llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | |
parent | ebe408ad8003c946ef871b955ab18e64e82697cb (diff) | |
download | llvm-39662abf720fc195b549246f32719d313f05a67f.zip llvm-39662abf720fc195b549246f32719d313f05a67f.tar.gz llvm-39662abf720fc195b549246f32719d313f05a67f.tar.bz2 |
[MIPatternMatch]: Add mi_match for MachineInstr
This utility allows more efficient start of pattern match.
Often MachineInstr(MI) is available and instead of using
mi_match(MI.getOperand(0).getReg(), MRI, ...) followed by
MRI.getVRegDef(Reg) that gives back MI we now use
mi_match(MI, MRI, ...).
Differential Revision: https://reviews.llvm.org/D99735
Diffstat (limited to 'llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp index 8801d37..c978b9e 100644 --- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -51,6 +51,37 @@ TEST_F(AArch64GISelMITest, MatchIntConstantRegister) { EXPECT_EQ(Src0, MIBCst.getReg(0)); } +TEST_F(AArch64GISelMITest, MachineInstrPtrBind) { + setUp(); + if (!TM) + return; + auto MIBAdd = B.buildAdd(LLT::scalar(64), Copies[0], Copies[1]); + // Test 'MachineInstr *' bind. + // Default mi_match. + MachineInstr *MIPtr = MIBAdd.getInstr(); + bool match = mi_match(MIPtr, *MRI, m_GAdd(m_Reg(), m_Reg())); + EXPECT_TRUE(match); + // Specialized mi_match for MachineInstr &. + MachineInstr &MI = *MIBAdd.getInstr(); + match = mi_match(MI, *MRI, m_GAdd(m_Reg(), m_Reg())); + EXPECT_TRUE(match); + // MachineInstrBuilder has automatic conversion to MachineInstr *. + match = mi_match(MIBAdd, *MRI, m_GAdd(m_Reg(), m_Reg())); + EXPECT_TRUE(match); + // Match instruction without def. + auto MIBBrcond = B.buildBrCond(Copies[0], B.getMBB()); + MachineInstr *MatchedMI; + match = mi_match(MIBBrcond, *MRI, m_MInstr(MatchedMI)); + EXPECT_TRUE(match); + EXPECT_TRUE(MIBBrcond.getInstr() == MatchedMI); + // Match instruction with two defs. + auto MIBUAddO = + B.buildUAddo(LLT::scalar(64), LLT::scalar(1), Copies[0], Copies[1]); + match = mi_match(MIBUAddO, *MRI, m_MInstr(MatchedMI)); + EXPECT_TRUE(match); + EXPECT_TRUE(MIBUAddO.getInstr() == MatchedMI); +} + TEST_F(AArch64GISelMITest, MatchBinaryOp) { setUp(); if (!TM) |