[llvm] 68295b1 - [PatternMatch] add matcher for FP infinity; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 11 13:52:15 PDT 2020


Author: Sanjay Patel
Date: 2020-03-11T16:52:08-04:00
New Revision: 68295b121a29c7a5f34bfaa7ec807fc56f0eb83f

URL: https://github.com/llvm/llvm-project/commit/68295b121a29c7a5f34bfaa7ec807fc56f0eb83f
DIFF: https://github.com/llvm/llvm-project/commit/68295b121a29c7a5f34bfaa7ec807fc56f0eb83f.diff

LOG: [PatternMatch] add matcher for FP infinity; NFC

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 9531914dfccb..03b92e524ad5 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -570,6 +570,15 @@ inline cstfp_pred_ty<is_nan> m_NaN() {
   return cstfp_pred_ty<is_nan>();
 }
 
+struct is_inf {
+  bool isValue(const APFloat &C) { return C.isInfinity(); }
+};
+/// Match a positive or negative infinity FP constant.
+/// For vectors, this includes constants with undefined elements.
+inline cstfp_pred_ty<is_inf> m_Inf() {
+  return cstfp_pred_ty<is_inf>();
+}
+
 struct is_any_zero_fp {
   bool isValue(const APFloat &C) { return C.isZero(); }
 };

diff  --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 4cc72c8eeedb..cb11d1ec71f2 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -1091,6 +1091,8 @@ TEST_F(PatternMatchTest, VectorUndefFloat) {
   Constant *VectorUndef = UndefValue::get(VectorTy);
   Constant *ScalarZero = Constant::getNullValue(ScalarTy);
   Constant *VectorZero = Constant::getNullValue(VectorTy);
+  Constant *ScalarPosInf = ConstantFP::getInfinity(ScalarTy, false);
+  Constant *ScalarNegInf = ConstantFP::getInfinity(ScalarTy, true);
 
   SmallVector<Constant *, 4> Elems;
   Elems.push_back(ScalarUndef);
@@ -1099,6 +1101,13 @@ TEST_F(PatternMatchTest, VectorUndefFloat) {
   Elems.push_back(ScalarZero);
   Constant *VectorZeroUndef = ConstantVector::get(Elems);
 
+  SmallVector<Constant *, 4> InfElems;
+  InfElems.push_back(ScalarPosInf);
+  InfElems.push_back(ScalarNegInf);
+  InfElems.push_back(ScalarUndef);
+  InfElems.push_back(ScalarPosInf);
+  Constant *VectorInfUndef = ConstantVector::get(InfElems);
+
   EXPECT_TRUE(match(ScalarUndef, m_Undef()));
   EXPECT_TRUE(match(VectorUndef, m_Undef()));
   EXPECT_FALSE(match(ScalarZero, m_Undef()));
@@ -1111,6 +1120,13 @@ TEST_F(PatternMatchTest, VectorUndefFloat) {
   EXPECT_TRUE(match(VectorZero, m_AnyZeroFP()));
   EXPECT_TRUE(match(VectorZeroUndef, m_AnyZeroFP()));
 
+  EXPECT_FALSE(match(ScalarUndef, m_Inf()));
+  EXPECT_FALSE(match(VectorUndef, m_Inf()));
+  EXPECT_FALSE(match(VectorZeroUndef, m_Inf()));
+  EXPECT_TRUE(match(ScalarPosInf, m_Inf()));
+  EXPECT_TRUE(match(ScalarNegInf, m_Inf()));
+  EXPECT_TRUE(match(VectorInfUndef, m_Inf()));
+
   const APFloat *C;
   // Regardless of whether undefs are allowed,
   // a fully undef constant does not match.


        


More information about the llvm-commits mailing list