[PATCH] D64037: [IR][PatternMatch] introduce m_Unless() matcher

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 06:36:36 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL367016: [IR][PatternMatch] introduce m_Unless() matcher (authored by lebedevri, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64037?vs=209729&id=211736#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64037/new/

https://reviews.llvm.org/D64037

Files:
  llvm/trunk/include/llvm/IR/PatternMatch.h
  llvm/trunk/unittests/IR/PatternMatch.cpp


Index: llvm/trunk/unittests/IR/PatternMatch.cpp
===================================================================
--- llvm/trunk/unittests/IR/PatternMatch.cpp
+++ llvm/trunk/unittests/IR/PatternMatch.cpp
@@ -454,6 +454,22 @@
           .match(NegOne));
 }
 
+TEST_F(PatternMatchTest, Unless) {
+  Value *X = IRB.CreateAdd(IRB.getInt32(1), IRB.getInt32(0));
+
+  EXPECT_TRUE(m_Add(m_One(), m_Zero()).match(X));
+  EXPECT_FALSE(m_Add(m_Zero(), m_One()).match(X));
+
+  EXPECT_FALSE(m_Unless(m_Add(m_One(), m_Zero())).match(X));
+  EXPECT_TRUE(m_Unless(m_Add(m_Zero(), m_One())).match(X));
+
+  EXPECT_TRUE(m_c_Add(m_One(), m_Zero()).match(X));
+  EXPECT_TRUE(m_c_Add(m_Zero(), m_One()).match(X));
+
+  EXPECT_FALSE(m_Unless(m_c_Add(m_One(), m_Zero())).match(X));
+  EXPECT_FALSE(m_Unless(m_c_Add(m_Zero(), m_One())).match(X));
+}
+
 TEST_F(PatternMatchTest, CommutativeDeferredValue) {
   Value *X = IRB.getInt32(1);
   Value *Y = IRB.getInt32(2);
Index: llvm/trunk/include/llvm/IR/PatternMatch.h
===================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h
+++ llvm/trunk/include/llvm/IR/PatternMatch.h
@@ -88,6 +88,20 @@
 /// Match an arbitrary Constant and ignore it.
 inline class_match<Constant> m_Constant() { return class_match<Constant>(); }
 
+/// Inverting matcher
+template <typename Ty> struct match_unless {
+  Ty M;
+
+  match_unless(const Ty &Matcher) : M(Matcher) {}
+
+  template <typename ITy> bool match(ITy *V) { return !M.match(V); }
+};
+
+/// Match if the inner matcher does *NOT* match.
+template <typename Ty> inline match_unless<Ty> m_Unless(const Ty &M) {
+  return match_unless<Ty>(M);
+}
+
 /// Matching combinators
 template <typename LTy, typename RTy> struct match_combine_or {
   LTy L;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64037.211736.patch
Type: text/x-patch
Size: 1773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190725/29d3afc0/attachment.bin>


More information about the llvm-commits mailing list