1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[PatternMatch] add matcher for FP infinity; NFC

This commit is contained in:
Sanjay Patel 2020-03-11 16:51:30 -04:00
parent 47d7e3782b
commit 699a46fa8b
2 changed files with 25 additions and 0 deletions

View File

@ -570,6 +570,15 @@ inline cstfp_pred_ty<is_nan> m_NaN() {
return cstfp_pred_ty<is_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 { struct is_any_zero_fp {
bool isValue(const APFloat &C) { return C.isZero(); } bool isValue(const APFloat &C) { return C.isZero(); }
}; };

View File

@ -1091,6 +1091,8 @@ TEST_F(PatternMatchTest, VectorUndefFloat) {
Constant *VectorUndef = UndefValue::get(VectorTy); Constant *VectorUndef = UndefValue::get(VectorTy);
Constant *ScalarZero = Constant::getNullValue(ScalarTy); Constant *ScalarZero = Constant::getNullValue(ScalarTy);
Constant *VectorZero = Constant::getNullValue(VectorTy); Constant *VectorZero = Constant::getNullValue(VectorTy);
Constant *ScalarPosInf = ConstantFP::getInfinity(ScalarTy, false);
Constant *ScalarNegInf = ConstantFP::getInfinity(ScalarTy, true);
SmallVector<Constant *, 4> Elems; SmallVector<Constant *, 4> Elems;
Elems.push_back(ScalarUndef); Elems.push_back(ScalarUndef);
@ -1099,6 +1101,13 @@ TEST_F(PatternMatchTest, VectorUndefFloat) {
Elems.push_back(ScalarZero); Elems.push_back(ScalarZero);
Constant *VectorZeroUndef = ConstantVector::get(Elems); 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(ScalarUndef, m_Undef()));
EXPECT_TRUE(match(VectorUndef, m_Undef())); EXPECT_TRUE(match(VectorUndef, m_Undef()));
EXPECT_FALSE(match(ScalarZero, 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(VectorZero, m_AnyZeroFP()));
EXPECT_TRUE(match(VectorZeroUndef, 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; const APFloat *C;
// Regardless of whether undefs are allowed, // Regardless of whether undefs are allowed,
// a fully undef constant does not match. // a fully undef constant does not match.