[llvm] r325542 - [GISel]: Add pattern matchers for G_BITCAST/PTRTOINT/INTTOPTR
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 15:11:53 PST 2018
Author: aditya_nandakumar
Date: Mon Feb 19 15:11:53 2018
New Revision: 325542
URL: http://llvm.org/viewvc/llvm-project?rev=325542&view=rev
Log:
[GISel]: Add pattern matchers for G_BITCAST/PTRTOINT/INTTOPTR
Adds pattern matchers for the above along with unit tests for the same.
https://reviews.llvm.org/D43479
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=325542&r1=325541&r2=325542&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h Mon Feb 19 15:11:53 2018
@@ -263,6 +263,24 @@ inline UnaryOp_match<SrcTy, TargetOpcode
}
template <typename SrcTy>
+inline UnaryOp_match<SrcTy, TargetOpcode::G_BITCAST>
+m_GBitcast(const SrcTy &Src) {
+ return UnaryOp_match<SrcTy, TargetOpcode::G_BITCAST>(Src);
+}
+
+template <typename SrcTy>
+inline UnaryOp_match<SrcTy, TargetOpcode::G_PTRTOINT>
+m_GPtrToInt(const SrcTy &Src) {
+ return UnaryOp_match<SrcTy, TargetOpcode::G_PTRTOINT>(Src);
+}
+
+template <typename SrcTy>
+inline UnaryOp_match<SrcTy, TargetOpcode::G_INTTOPTR>
+m_GIntToPtr(const SrcTy &Src) {
+ return UnaryOp_match<SrcTy, TargetOpcode::G_INTTOPTR>(Src);
+}
+
+template <typename SrcTy>
inline UnaryOp_match<SrcTy, TargetOpcode::G_FPTRUNC>
m_GFPTrunc(const SrcTy &Src) {
return UnaryOp_match<SrcTy, TargetOpcode::G_FPTRUNC>(Src);
Modified: llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp?rev=325542&r1=325541&r2=325542&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp Mon Feb 19 15:11:53 2018
@@ -314,9 +314,23 @@ TEST(PatternMatchInstr, MatchSpecificTyp
LLT v2s32 = LLT::vector(2, 32);
auto MIBCast = B.buildCast(v2s32, Copies[0]);
ASSERT_TRUE(
+ mi_match(MIBCast->getOperand(0).getReg(), MRI, m_GBitcast(m_Reg())));
+ ASSERT_TRUE(
mi_match(MIBCast->getOperand(0).getReg(), MRI, m_SpecificType(v2s32)));
ASSERT_TRUE(
mi_match(MIBCast->getOperand(1).getReg(), MRI, m_SpecificType(s64)));
+
+ // Build a PTRToInt and INTTOPTR and match and test them.
+ LLT PtrTy = LLT::pointer(0, 64);
+ auto MIBIntToPtr = B.buildCast(PtrTy, Copies[0]);
+ auto MIBPtrToInt = B.buildCast(s64, MIBIntToPtr);
+ unsigned Src0;
+
+ // match the ptrtoint(inttoptr reg)
+ bool match = mi_match(MIBPtrToInt->getOperand(0).getReg(), MRI,
+ m_GPtrToInt(m_GIntToPtr(m_Reg(Src0))));
+ ASSERT_TRUE(match);
+ ASSERT_EQ(Src0, Copies[0]);
}
TEST(PatternMatchInstr, MatchCombinators) {
More information about the llvm-commits
mailing list