/// vector has an exact multiplicative inverse for each element in the vector.
bool hasExactInverseFP() const;
+ /// Return true if this is a floating-point NaN constant or a vector
+ /// floating-point constant with all NaN elements.
+ bool isNaN() const;
+
/// Return true if evaluation of this constant could trap. This is true for
/// things like constant expressions that could divide by zero.
bool canTrap() const;
return getTrue(RetTy);
}
+ // NaN is unordered; NaN is not ordered.
+ assert((FCmpInst::isOrdered(Pred) || FCmpInst::isUnordered(Pred)) &&
+ "Comparison must be either ordered or unordered");
+ if (match(RHS, m_NaN()))
+ return ConstantInt::get(RetTy, CmpInst::isUnordered(Pred));
+
// fcmp pred x, undef and fcmp pred undef, x
// fold to true if unordered, false if ordered
if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS)) {
// Handle fcmp with constant RHS.
const APFloat *C;
if (match(RHS, m_APFloat(C))) {
- // If the constant is a nan, see if we can fold the comparison based on it.
- if (C->isNaN()) {
- if (FCmpInst::isOrdered(Pred)) // True "if ordered and foo"
- return getFalse(RetTy);
- assert(FCmpInst::isUnordered(Pred) &&
- "Comparison must be either ordered or unordered!");
- // True if unordered.
- return getTrue(RetTy);
- }
// Check whether the constant is an infinity.
if (C->isInfinity()) {
if (C->isNegative()) {
return true;
}
+bool Constant::isNaN() const {
+ if (auto *CFP = dyn_cast<ConstantFP>(this))
+ return CFP->isNaN();
+ if (!getType()->isVectorTy())
+ return false;
+ for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) {
+ auto *CFP = dyn_cast_or_null<ConstantFP>(this->getAggregateElement(i));
+ if (!CFP || !CFP->isNaN())
+ return false;
+ }
+ return true;
+}
+
/// Constructor to create a '0' constant of arbitrary type.
Constant *Constant::getNullValue(Type *Ty) {
switch (Ty->getTypeID()) {