[llvm] r363424 - [GISel]: Fix pattern matcher for m_OneUse
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 10:19:37 PDT 2019
Author: aditya_nandakumar
Date: Fri Jun 14 10:19:37 2019
New Revision: 363424
URL: http://llvm.org/viewvc/llvm-project?rev=363424&view=rev
Log:
[GISel]: Fix pattern matcher for m_OneUse
https://reviews.llvm.org/D63302
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h?rev=363424&r1=363423&r2=363424&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h Fri Jun 14 10:19:37 2019
@@ -30,8 +30,7 @@ template <typename SubPatternT> struct O
SubPatternT SubPat;
OneUse_match(const SubPatternT &SP) : SubPat(SP) {}
- template <typename OpTy>
- bool match(const MachineRegisterInfo &MRI, unsigned Reg) {
+ bool match(MachineRegisterInfo &MRI, unsigned Reg) {
return MRI.hasOneUse(Reg) && SubPat.match(MRI, Reg);
}
};
Modified: llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp?rev=363424&r1=363423&r2=363424&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp Fri Jun 14 10:19:37 2019
@@ -484,6 +484,31 @@ TEST(PatternMatchInstr, MatchCombinators
m_any_of(m_SpecificType(LLT::scalar(16)), m_GSub(m_Reg(), m_Reg())));
EXPECT_FALSE(match);
}
+
+TEST(PatternMatchInstr, MatchMiscellaneous) {
+ LLVMContext Context;
+ std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
+ if (!TM)
+ return;
+ auto ModuleMMIPair = createDummyModule(Context, *TM, "");
+ MachineFunction *MF =
+ getMFFromMMI(ModuleMMIPair.first.get(), ModuleMMIPair.second.get());
+ SmallVector<unsigned, 4> Copies;
+ collectCopies(Copies, MF);
+ MachineBasicBlock *EntryMBB = &*MF->begin();
+ MachineIRBuilder B(*MF);
+ MachineRegisterInfo &MRI = MF->getRegInfo();
+ B.setInsertPt(*EntryMBB, EntryMBB->end());
+ LLT s64 = LLT::scalar(64);
+ auto MIBAdd = B.buildAdd(s64, Copies[0], Copies[1]);
+ // Make multiple uses of this add.
+ B.buildCast(LLT::pointer(0, 32), MIBAdd);
+ B.buildCast(LLT::pointer(1, 32), MIBAdd);
+ bool match = mi_match(MIBAdd.getReg(0), MRI, m_GAdd(m_Reg(), m_Reg()));
+ EXPECT_TRUE(match);
+ match = mi_match(MIBAdd.getReg(0), MRI, m_OneUse(m_GAdd(m_Reg(), m_Reg())));
+ EXPECT_FALSE(match);
+}
} // namespace
int main(int argc, char **argv) {
More information about the llvm-commits
mailing list