/// \returns true if this APInt is positive.
bool isStrictlyPositive() const { return isNonNegative() && !isNullValue(); }
+ /// Determine if this APInt Value is non-positive (<= 0).
+ ///
+ /// \returns true if this APInt is non-positive.
+ bool isNonPositive() const { return !isStrictlyPositive(); }
+
/// Determine if all bits are set
///
/// This checks to see if the value has all bits of the APInt are set or not.
struct is_nonnegative {
bool isValue(const APInt &C) { return C.isNonNegative(); }
};
-/// Match an integer or vector of nonnegative values.
+/// Match an integer or vector of non-negative values.
/// For vectors, this includes constants with undefined elements.
inline cst_pred_ty<is_nonnegative> m_NonNegative() {
return cst_pred_ty<is_nonnegative>();
return V;
}
+struct is_strictlypositive {
+ bool isValue(const APInt &C) { return C.isStrictlyPositive(); }
+};
+/// Match an integer or vector of strictly positive values.
+/// For vectors, this includes constants with undefined elements.
+inline cst_pred_ty<is_strictlypositive> m_StrictlyPositive() {
+ return cst_pred_ty<is_strictlypositive>();
+}
+inline api_pred_ty<is_strictlypositive> m_StrictlyPositive(const APInt *&V) {
+ return V;
+}
+
+struct is_nonpositive {
+ bool isValue(const APInt &C) { return C.isNonPositive(); }
+};
+/// Match an integer or vector of non-positive values.
+/// For vectors, this includes constants with undefined elements.
+inline cst_pred_ty<is_nonpositive> m_NonPositive() {
+ return cst_pred_ty<is_nonpositive>();
+}
+inline api_pred_ty<is_nonpositive> m_NonPositive(const APInt *&V) { return V; }
+
struct is_one {
bool isValue(const APInt &C) { return C.isOneValue(); }
};
}
}
+TEST(APIntTest, SignbitZeroChecks) {
+ EXPECT_TRUE(APInt(8, -1).isNegative());
+ EXPECT_FALSE(APInt(8, -1).isNonNegative());
+ EXPECT_FALSE(APInt(8, -1).isStrictlyPositive());
+ EXPECT_TRUE(APInt(8, -1).isNonPositive());
+
+ EXPECT_FALSE(APInt(8, 0).isNegative());
+ EXPECT_TRUE(APInt(8, 0).isNonNegative());
+ EXPECT_FALSE(APInt(8, 0).isStrictlyPositive());
+ EXPECT_TRUE(APInt(8, 0).isNonPositive());
+
+ EXPECT_FALSE(APInt(8, 1).isNegative());
+ EXPECT_TRUE(APInt(8, 1).isNonNegative());
+ EXPECT_TRUE(APInt(8, 1).isStrictlyPositive());
+ EXPECT_FALSE(APInt(8, 1).isNonPositive());
+}
+
} // end anonymous namespace
.match(NegOne));
}
+TEST_F(PatternMatchTest, SignbitZeroChecks) {
+ 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_Negative().match(NegOne));
+ EXPECT_FALSE(m_NonNegative().match(NegOne));
+ EXPECT_FALSE(m_StrictlyPositive().match(NegOne));
+ EXPECT_TRUE(m_NonPositive().match(NegOne));
+
+ EXPECT_FALSE(m_Negative().match(Zero));
+ EXPECT_TRUE(m_NonNegative().match(Zero));
+ EXPECT_FALSE(m_StrictlyPositive().match(Zero));
+ EXPECT_TRUE(m_NonPositive().match(Zero));
+
+ EXPECT_FALSE(m_Negative().match(One));
+ EXPECT_TRUE(m_NonNegative().match(One));
+ EXPECT_TRUE(m_StrictlyPositive().match(One));
+ EXPECT_FALSE(m_NonPositive().match(One));
+}
+
TEST_F(PatternMatchTest, SpecificIntUGE) {
Type *IntTy = IRB.getInt32Ty();
unsigned BitWidth = IntTy->getScalarSizeInBits();