summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-07-10 16:07:35 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2019-07-10 16:07:35 +0000
commitc5f92bd67beabfc2c8d20af9a799a8c9c8f7ed95 (patch)
tree41cddfc863815e553dfedf3c22bd89362cd5b2de
parentbf223dff7ef076733c9b28c992028ee2dc8c9114 (diff)
downloadbcm5719-llvm-c5f92bd67beabfc2c8d20af9a799a8c9c8f7ed95.tar.gz
bcm5719-llvm-c5f92bd67beabfc2c8d20af9a799a8c9c8f7ed95.zip
[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. llvm-svn: 365652
-rw-r--r--llvm/include/llvm/IR/PatternMatch.h44
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp3
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp3
-rw-r--r--llvm/unittests/IR/PatternMatch.cpp387
4 files changed, 417 insertions, 20 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 1a11af27d1a..0f03d7cc56b 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -418,16 +418,42 @@ inline cst_pred_ty<is_lowbit_mask> m_LowBitMask() {
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); }
-};
-/// 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;
+ 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 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;
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 4c818193ced..3a4283ae540 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3316,7 +3316,8 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ,
// 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
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 0bbecde2184..c821292400c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -48,7 +48,8 @@ reassociateShiftAmtsOfTwoSameDirectionShifts(BinaryOperator *Sh0,
// 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);
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 8ea7a68b27c..600494fba26 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -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_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_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_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_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_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) {
OpenPOWER on IntegriCloud