[llvm] r365652 - [PatternMatch] Generalize m_SpecificInt_ULT() to take ICmpInst::Predicate
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 09:07:35 PDT 2019
Author: lebedevri
Date: Wed Jul 10 09:07:35 2019
New Revision: 365652
URL: http://llvm.org/viewvc/llvm-project?rev=365652&view=rev
Log:
[PatternMatch] Generalize m_SpecificInt_ULT() to take ICmpInst::Predicate
As discussed in the original review, this may be useful,
so let's just do it.
Modified:
llvm/trunk/include/llvm/IR/PatternMatch.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
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=365652&r1=365651&r2=365652&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Wed Jul 10 09:07:35 2019
@@ -418,16 +418,42 @@ inline cst_pred_ty<is_lowbit_mask> m_Low
return cst_pred_ty<is_lowbit_mask>();
}
-struct is_unsigned_less_than {
+struct icmp_pred_with_threshold {
+ ICmpInst::Predicate Pred;
const APInt *Thr;
- bool isValue(const APInt &C) { return C.ult(*Thr); }
+ bool isValue(const APInt &C) {
+ switch (Pred) {
+ case ICmpInst::Predicate::ICMP_EQ:
+ return C.eq(*Thr);
+ case ICmpInst::Predicate::ICMP_NE:
+ return C.ne(*Thr);
+ case ICmpInst::Predicate::ICMP_UGT:
+ return C.ugt(*Thr);
+ case ICmpInst::Predicate::ICMP_UGE:
+ return C.uge(*Thr);
+ case ICmpInst::Predicate::ICMP_ULT:
+ return C.ult(*Thr);
+ case ICmpInst::Predicate::ICMP_ULE:
+ return C.ule(*Thr);
+ case ICmpInst::Predicate::ICMP_SGT:
+ return C.sgt(*Thr);
+ case ICmpInst::Predicate::ICMP_SGE:
+ return C.sge(*Thr);
+ case ICmpInst::Predicate::ICMP_SLT:
+ return C.slt(*Thr);
+ case ICmpInst::Predicate::ICMP_SLE:
+ return C.sle(*Thr);
+ default:
+ llvm_unreachable("Unhandled ICmp predicate");
+ }
+ }
};
-/// 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;
+/// Match an integer or vector with every element comparing 'pred' (eg/ne/...)
+/// to Threshold. For vectors, this includes constants with undefined elements.
+inline cst_pred_ty<icmp_pred_with_threshold>
+m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold) {
+ cst_pred_ty<icmp_pred_with_threshold> P;
+ P.Pred = Predicate;
P.Thr = &Threshold;
return P;
}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=365652&r1=365651&r2=365652&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Jul 10 09:07:35 2019
@@ -3316,7 +3316,8 @@ foldShiftIntoShiftInAnotherHandOfAndInIC
// Is the new shift amount smaller than the bit width?
// FIXME: could also rely on ConstantRange.
unsigned BitWidth = X->getType()->getScalarSizeInBits();
- if (!match(NewShAmt, m_SpecificInt_ULT(APInt(BitWidth, BitWidth))))
+ if (!match(NewShAmt, m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
+ APInt(BitWidth, BitWidth))))
return nullptr;
// All good, we can do this fold. The shift is the same that was for X.
Value *T0 = XShiftOpcode == Instruction::BinaryOps::LShr
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp?rev=365652&r1=365651&r2=365652&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp Wed Jul 10 09:07:35 2019
@@ -48,7 +48,8 @@ reassociateShiftAmtsOfTwoSameDirectionSh
// Is the new shift amount smaller than the bit width?
// FIXME: could also rely on ConstantRange.
unsigned BitWidth = X->getType()->getScalarSizeInBits();
- if (!match(NewShAmt, m_SpecificInt_ULT(APInt(BitWidth, BitWidth))))
+ if (!match(NewShAmt, m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT,
+ APInt(BitWidth, BitWidth))))
return nullptr;
// All good, we can do this fold.
BinaryOperator *NewShift = BinaryOperator::Create(ShiftOpcode, X, NewShAmt);
Modified: llvm/trunk/unittests/IR/PatternMatch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/PatternMatch.cpp?rev=365652&r1=365651&r2=365652&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/PatternMatch.cpp (original)
+++ llvm/trunk/unittests/IR/PatternMatch.cpp Wed Jul 10 09:07:35 2019
@@ -64,6 +64,162 @@ TEST_F(PatternMatchTest, OneUse) {
EXPECT_FALSE(m_OneUse(m_Value()).match(Leaf));
}
+TEST_F(PatternMatchTest, SpecificIntEQ) {
+ 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_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_EQ, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntNE) {
+ 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_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_NE, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntUGT) {
+ 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_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGT, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntUGE) {
+ 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_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
TEST_F(PatternMatchTest, SpecificIntULT) {
Type *IntTy = IRB.getInt32Ty();
unsigned BitWidth = IntTy->getScalarSizeInBits();
@@ -72,17 +228,230 @@ TEST_F(PatternMatchTest, SpecificIntULT)
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));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULT, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntULE) {
+ 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_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_ULE, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntSGT) {
+ 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_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGT, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntSGE) {
+ 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_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SGE, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntSLT) {
+ 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_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLT, APInt(BitWidth, -1))
+ .match(NegOne));
+}
+
+TEST_F(PatternMatchTest, SpecificIntSLE) {
+ 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_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 0))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 0))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 0))
+ .match(NegOne));
+
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 1))
+ .match(Zero));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, 1))
+ .match(NegOne));
+
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
+ .match(Zero));
+ EXPECT_FALSE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
+ .match(One));
+ EXPECT_TRUE(
+ m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_SLE, APInt(BitWidth, -1))
+ .match(NegOne));
}
TEST_F(PatternMatchTest, CommutativeDeferredValue) {
More information about the llvm-commits
mailing list