diff options
author | Aditya Nandakumar <aditya_nandakumar@apple.com> | 2018-02-19 23:11:53 +0000 |
---|---|---|
committer | Aditya Nandakumar <aditya_nandakumar@apple.com> | 2018-02-19 23:11:53 +0000 |
commit | bab2d3e2b972549d51791a4a14ff86d88dc78077 (patch) | |
tree | 11a2c2087159c8df8176db294c46cb678d65dedc | |
parent | 2816560b2c2c05c78c00a1df5849566ff093bb86 (diff) | |
download | bcm5719-llvm-bab2d3e2b972549d51791a4a14ff86d88dc78077.tar.gz bcm5719-llvm-bab2d3e2b972549d51791a4a14ff86d88dc78077.zip |
[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
llvm-svn: 325542
-rw-r--r-- | llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h | 18 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp | 14 |
2 files changed, 32 insertions, 0 deletions
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h index fc910342760..8adeb4969e6 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h @@ -263,6 +263,24 @@ inline UnaryOp_match<SrcTy, TargetOpcode::G_TRUNC> m_GTrunc(const SrcTy &Src) { } 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); diff --git a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp index d01a1293f7f..b4281013350 100644 --- a/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp @@ -314,9 +314,23 @@ TEST(PatternMatchInstr, MatchSpecificType) { 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) { |