[llvm] r364711 - [IR][Patternmatch] Add m_SpecificInt_ULT() predicate
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 29 04:51:37 PDT 2019
Author: lebedevri
Date: Sat Jun 29 04:51:37 2019
New Revision: 364711
URL: http://llvm.org/viewvc/llvm-project?rev=364711&view=rev
Log:
[IR][Patternmatch] Add m_SpecificInt_ULT() predicate
Summary:
Match an integer or vector with every element unsigned less than the
Threshold. For vectors, this includes constants with undefined elements.
FIXME: is it worth generalizing this to simply take ICmpInst::Predicate?
Reviewers: craig.topper, spatel, nikic
Reviewed By: spatel
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63811
Modified:
llvm/trunk/include/llvm/IR/PatternMatch.h
llvm/trunk/unittests/IR/PatternMatch.cpp
Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=364711&r1=364710&r2=364711&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Sat Jun 29 04:51:37 2019
@@ -418,6 +418,20 @@ inline cst_pred_ty<is_lowbit_mask> m_Low
return cst_pred_ty<is_lowbit_mask>();
}
+struct is_unsigned_less_than {
+ const APInt *Thr;
+ bool isValue(const APInt &C) { return C.ult(*Thr); }
+};
+/// Match an integer or vector with every element unsigned less than the
+/// Threshold. For vectors, this includes constants with undefined elements.
+/// FIXME: is it worth generalizing this to simply take ICmpInst::Predicate?
+inline cst_pred_ty<is_unsigned_less_than>
+m_SpecificInt_ULT(const APInt &Threshold) {
+ cst_pred_ty<is_unsigned_less_than> P;
+ P.Thr = &Threshold;
+ return P;
+}
+
struct is_nan {
bool isValue(const APFloat &C) { return C.isNaN(); }
};
Modified: llvm/trunk/unittests/IR/PatternMatch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/PatternMatch.cpp?rev=364711&r1=364710&r2=364711&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/PatternMatch.cpp (original)
+++ llvm/trunk/unittests/IR/PatternMatch.cpp Sat Jun 29 04:51:37 2019
@@ -64,6 +64,27 @@ TEST_F(PatternMatchTest, OneUse) {
EXPECT_FALSE(m_OneUse(m_Value()).match(Leaf));
}
+TEST_F(PatternMatchTest, SpecificIntULT) {
+ Type *IntTy = IRB.getInt32Ty();
+ unsigned BitWidth = IntTy->getScalarSizeInBits();
+
+ Value *Zero = ConstantInt::get(IntTy, 0);
+ Value *One = ConstantInt::get(IntTy, 1);
+ Value *NegOne = ConstantInt::get(IntTy, -1);
+
+ EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 0)).match(Zero));
+ EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 0)).match(One));
+ EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 0)).match(NegOne));
+
+ EXPECT_TRUE(m_SpecificInt_ULT(APInt(BitWidth, 1)).match(Zero));
+ EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 1)).match(One));
+ EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 1)).match(NegOne));
+
+ EXPECT_TRUE(m_SpecificInt_ULT(APInt(BitWidth, -1)).match(Zero));
+ EXPECT_TRUE(m_SpecificInt_ULT(APInt(BitWidth, -1)).match(One));
+ EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, -1)).match(NegOne));
+}
+
TEST_F(PatternMatchTest, CommutativeDeferredValue) {
Value *X = IRB.getInt32(1);
Value *Y = IRB.getInt32(2);
More information about the llvm-commits
mailing list