llvm.org GIT mirror llvm / e30b1c0
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364711 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Lebedev 1 year, 5 months ago
2 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
415415 /// For vectors, this includes constants with undefined elements.
416416 inline cst_pred_ty m_LowBitMask() {
417417 return cst_pred_ty();
418 }
419
420 struct is_unsigned_less_than {
421 const APInt *Thr;
422 bool isValue(const APInt &C) { return C.ult(*Thr); }
423 };
424 /// Match an integer or vector with every element unsigned less than the
425 /// Threshold. For vectors, this includes constants with undefined elements.
426 /// FIXME: is it worth generalizing this to simply take ICmpInst::Predicate?
427 inline cst_pred_ty
428 m_SpecificInt_ULT(const APInt &Threshold) {
429 cst_pred_ty P;
430 P.Thr = &Threshold;
431 return P;
418432 }
419433
420434 struct is_nan {
6161
6262 EXPECT_FALSE(m_OneUse(m_Value()).match(Two));
6363 EXPECT_FALSE(m_OneUse(m_Value()).match(Leaf));
64 }
65
66 TEST_F(PatternMatchTest, SpecificIntULT) {
67 Type *IntTy = IRB.getInt32Ty();
68 unsigned BitWidth = IntTy->getScalarSizeInBits();
69
70 Value *Zero = ConstantInt::get(IntTy, 0);
71 Value *One = ConstantInt::get(IntTy, 1);
72 Value *NegOne = ConstantInt::get(IntTy, -1);
73
74 EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 0)).match(Zero));
75 EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 0)).match(One));
76 EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 0)).match(NegOne));
77
78 EXPECT_TRUE(m_SpecificInt_ULT(APInt(BitWidth, 1)).match(Zero));
79 EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 1)).match(One));
80 EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, 1)).match(NegOne));
81
82 EXPECT_TRUE(m_SpecificInt_ULT(APInt(BitWidth, -1)).match(Zero));
83 EXPECT_TRUE(m_SpecificInt_ULT(APInt(BitWidth, -1)).match(One));
84 EXPECT_FALSE(m_SpecificInt_ULT(APInt(BitWidth, -1)).match(NegOne));
6485 }
6586
6687 TEST_F(PatternMatchTest, CommutativeDeferredValue) {