llvm.org GIT mirror llvm / 9ba5450
[GISel]: Fix pattern matcher for m_OneUse https://reviews.llvm.org/D63302 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363424 91177308-0d34-0410-b5e6-96231b3b80d8 Aditya Nandakumar a month ago
2 changed file(s) with 26 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2929 SubPatternT SubPat;
3030 OneUse_match(const SubPatternT &SP) : SubPat(SP) {}
3131
32 template
33 bool match(const MachineRegisterInfo &MRI, unsigned Reg) {
32 bool match(MachineRegisterInfo &MRI, unsigned Reg) {
3433 return MRI.hasOneUse(Reg) && SubPat.match(MRI, Reg);
3534 }
3635 };
483483 m_any_of(m_SpecificType(LLT::scalar(16)), m_GSub(m_Reg(), m_Reg())));
484484 EXPECT_FALSE(match);
485485 }
486
487 TEST(PatternMatchInstr, MatchMiscellaneous) {
488 LLVMContext Context;
489 std::unique_ptr TM = createTargetMachine();
490 if (!TM)
491 return;
492 auto ModuleMMIPair = createDummyModule(Context, *TM, "");
493 MachineFunction *MF =
494 getMFFromMMI(ModuleMMIPair.first.get(), ModuleMMIPair.second.get());
495 SmallVector Copies;
496 collectCopies(Copies, MF);
497 MachineBasicBlock *EntryMBB = &*MF->begin();
498 MachineIRBuilder B(*MF);
499 MachineRegisterInfo &MRI = MF->getRegInfo();
500 B.setInsertPt(*EntryMBB, EntryMBB->end());
501 LLT s64 = LLT::scalar(64);
502 auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
503 // Make multiple uses of this add.
504 B.buildCast(LLT::pointer(0, 32), MIBAdd);
505 B.buildCast(LLT::pointer(1, 32), MIBAdd);
506 bool match = mi_match(MIBAdd.getReg(0), MRI, m_GAdd(m_Reg(), m_Reg()));
507 EXPECT_TRUE(match);
508 match = mi_match(MIBAdd.getReg(0), MRI, m_OneUse(m_GAdd(m_Reg(), m_Reg())));
509 EXPECT_FALSE(match);
510 }
486511 } // namespace
487512
488513 int main(int argc, char **argv) {