[PATCH] D63811: [IR][Patternmatch] Add m_SpecificInt_ULT() predicate

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 02:52:26 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: craig.topper, spatel, nikic.
lebedev.ri added a project: LLVM.
lebedev.ri added a child revision: D63812: [InstCombine] Shift amount reassociation (PR42391).

Match an integer or vector with every element unsigned less than the
Threshold. For vectors, this includes constants with undefined elements.


Repository:
  rL LLVM

https://reviews.llvm.org/D63811

Files:
  include/llvm/IR/PatternMatch.h
  unittests/IR/PatternMatch.cpp


Index: unittests/IR/PatternMatch.cpp
===================================================================
--- unittests/IR/PatternMatch.cpp
+++ unittests/IR/PatternMatch.cpp
@@ -64,6 +64,27 @@
   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);
Index: include/llvm/IR/PatternMatch.h
===================================================================
--- include/llvm/IR/PatternMatch.h
+++ include/llvm/IR/PatternMatch.h
@@ -418,6 +418,19 @@
   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.
+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(); }
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63811.206620.patch
Type: text/x-patch
Size: 2015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190626/ddfb0411/attachment.bin>


More information about the llvm-commits mailing list