[PATCH] D43479: [GISel][NFCish]: Add pattern matchers for G_BITCAST/PTRTOINT/INTTOPTR

Aditya Nandakumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 13:21:12 PST 2018


aditya_nandakumar created this revision.
aditya_nandakumar added reviewers: qcolombet, dsanders, bogner, rovka.

Adds pattern matchers for the above along with unit tests for the same.


Repository:
  rL LLVM

https://reviews.llvm.org/D43479

Files:
  include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
  unittests/CodeGen/GlobalISel/PatternMatchTest.cpp


Index: unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
===================================================================
--- unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
+++ unittests/CodeGen/GlobalISel/PatternMatchTest.cpp
@@ -313,10 +313,24 @@
   // Try to match the destination type of a bitcast.
   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) {
Index: include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -262,6 +262,24 @@
   return UnaryOp_match<SrcTy, TargetOpcode::G_TRUNC>(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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43479.134963.patch
Type: text/x-patch
Size: 2149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180219/3486f4ae/attachment.bin>


More information about the llvm-commits mailing list