mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[IR][PatternMatch] introduce m_Unless() matcher
Summary: I don't think it already exists? I don't see it at least. It is important to have it because else we'll do some checks after `match()`, and that may result in missed folds in commutative nodes. Reviewers: spatel, craig.topper, RKSimon, majnemer Reviewed By: spatel Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64037 llvm-svn: 367016
This commit is contained in:
parent
4e4ee627cd
commit
784d5ec89a
@ -88,6 +88,20 @@ inline class_match<UndefValue> m_Undef() { return class_match<UndefValue>(); }
|
||||
/// 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;
|
||||
|
@ -454,6 +454,22 @@ TEST_F(PatternMatchTest, SpecificIntSLE) {
|
||||
.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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user