[llvm] 86d0b52 - ValueTracking: Expand signature of isKnownNeverInfinity/NaN
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 12:43:08 PDT 2023
Author: Matt Arsenault
Date: 2023-05-16T20:42:58+01:00
New Revision: 86d0b524f36302cac3f0cdf5c617052e9fad7026
URL: https://github.com/llvm/llvm-project/commit/86d0b524f36302cac3f0cdf5c617052e9fad7026
DIFF: https://github.com/llvm/llvm-project/commit/86d0b524f36302cac3f0cdf5c617052e9fad7026.diff
LOG: ValueTracking: Expand signature of isKnownNeverInfinity/NaN
This is in preparation for replacing the implementation
with a wrapper around computeKnownFPClass.
Added:
Modified:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index 0b77580d5e7d8..b2716b264fdb8 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -443,13 +443,19 @@ bool CannotBeNegativeZero(const Value *V, const TargetLibraryInfo *TLI,
/// -0 --> true
/// x > +0 --> true
/// x < -0 --> false
-bool CannotBeOrderedLessThanZero(const Value *V, const TargetLibraryInfo *TLI);
+bool CannotBeOrderedLessThanZero(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI);
/// Return true if the floating-point scalar value is not an infinity or if
/// the floating-point vector value has no infinities. Return false if a value
/// could ever be infinity.
-bool isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
- unsigned Depth = 0);
+bool isKnownNeverInfinity(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI = nullptr,
+ unsigned Depth = 0, AssumptionCache *AC = nullptr,
+ const Instruction *CtxI = nullptr,
+ const DominatorTree *DT = nullptr,
+ OptimizationRemarkEmitter *ORE = nullptr,
+ bool UseInstrInfo = true);
/// Return true if the floating-point value can never contain a NaN or infinity.
inline bool isKnownNeverInfOrNaN(
@@ -465,8 +471,13 @@ inline bool isKnownNeverInfOrNaN(
/// Return true if the floating-point scalar value is not a NaN or if the
/// floating-point vector value has no NaN elements. Return false if a value
/// could ever be NaN.
-bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
- unsigned Depth = 0);
+bool isKnownNeverNaN(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI = nullptr, unsigned Depth = 0,
+ AssumptionCache *AC = nullptr,
+ const Instruction *CtxI = nullptr,
+ const DominatorTree *DT = nullptr,
+ OptimizationRemarkEmitter *ORE = nullptr,
+ bool UseInstrInfo = true);
/// Return true if we can prove that the specified FP value's sign bit is 0.
///
@@ -475,7 +486,8 @@ bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
/// -0 --> false
/// x > +0 --> true
/// x < -0 --> false
-bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI);
+bool SignBitMustBeZero(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI);
/// If the specified value can be set by repeating the same byte in memory,
/// return the i8 value that it is represented with. This is true for all i8
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 50e39977af53d..89ac18bbddf5f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1949,7 +1949,8 @@ static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,
return nullptr;
}
-static Value *simplifyAndOrOfFCmps(const TargetLibraryInfo *TLI, FCmpInst *LHS,
+static Value *simplifyAndOrOfFCmps(const DataLayout &DL,
+ const TargetLibraryInfo *TLI, FCmpInst *LHS,
FCmpInst *RHS, bool IsAnd) {
Value *LHS0 = LHS->getOperand(0), *LHS1 = LHS->getOperand(1);
Value *RHS0 = RHS->getOperand(0), *RHS1 = RHS->getOperand(1);
@@ -1967,8 +1968,8 @@ static Value *simplifyAndOrOfFCmps(const TargetLibraryInfo *TLI, FCmpInst *LHS,
// (fcmp uno NNAN, X) | (fcmp uno Y, X) --> fcmp uno Y, X
// (fcmp uno X, NNAN) | (fcmp uno X, Y) --> fcmp uno X, Y
// (fcmp uno X, NNAN) | (fcmp uno Y, X) --> fcmp uno Y, X
- if (((LHS1 == RHS0 || LHS1 == RHS1) && isKnownNeverNaN(LHS0, TLI)) ||
- ((LHS0 == RHS0 || LHS0 == RHS1) && isKnownNeverNaN(LHS1, TLI)))
+ if (((LHS1 == RHS0 || LHS1 == RHS1) && isKnownNeverNaN(LHS0, DL, TLI)) ||
+ ((LHS0 == RHS0 || LHS0 == RHS1) && isKnownNeverNaN(LHS1, DL, TLI)))
return RHS;
// (fcmp ord X, Y) & (fcmp ord NNAN, X) --> fcmp ord X, Y
@@ -1979,8 +1980,8 @@ static Value *simplifyAndOrOfFCmps(const TargetLibraryInfo *TLI, FCmpInst *LHS,
// (fcmp uno Y, X) | (fcmp uno NNAN, X) --> fcmp uno Y, X
// (fcmp uno X, Y) | (fcmp uno X, NNAN) --> fcmp uno X, Y
// (fcmp uno Y, X) | (fcmp uno X, NNAN) --> fcmp uno Y, X
- if (((RHS1 == LHS0 || RHS1 == LHS1) && isKnownNeverNaN(RHS0, TLI)) ||
- ((RHS0 == LHS0 || RHS0 == LHS1) && isKnownNeverNaN(RHS1, TLI)))
+ if (((RHS1 == LHS0 || RHS1 == LHS1) && isKnownNeverNaN(RHS0, DL, TLI)) ||
+ ((RHS0 == LHS0 || RHS0 == LHS1) && isKnownNeverNaN(RHS1, DL, TLI)))
return LHS;
}
@@ -2008,7 +2009,7 @@ static Value *simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0,
auto *FCmp0 = dyn_cast<FCmpInst>(Op0);
auto *FCmp1 = dyn_cast<FCmpInst>(Op1);
if (FCmp0 && FCmp1)
- V = simplifyAndOrOfFCmps(Q.TLI, FCmp0, FCmp1, IsAnd);
+ V = simplifyAndOrOfFCmps(Q.DL, Q.TLI, FCmp0, FCmp1, IsAnd);
if (!V)
return nullptr;
@@ -4014,8 +4015,8 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
// Fold (un)ordered comparison if we can determine there are no NaNs.
if (Pred == FCmpInst::FCMP_UNO || Pred == FCmpInst::FCMP_ORD)
- if (FMF.noNaNs() ||
- (isKnownNeverNaN(LHS, Q.TLI) && isKnownNeverNaN(RHS, Q.TLI)))
+ if (FMF.noNaNs() || (isKnownNeverNaN(LHS, Q.DL, Q.TLI) &&
+ isKnownNeverNaN(RHS, Q.DL, Q.TLI)))
return ConstantInt::get(RetTy, Pred == FCmpInst::FCMP_ORD);
// NaN is unordered; NaN is not ordered.
@@ -4077,18 +4078,20 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
// LHS == Inf
- if (Pred == FCmpInst::FCMP_OEQ && isKnownNeverInfinity(LHS, Q.TLI))
+ if (Pred == FCmpInst::FCMP_OEQ && isKnownNeverInfinity(LHS, Q.DL, Q.TLI))
return getFalse(RetTy);
// LHS != Inf
- if (Pred == FCmpInst::FCMP_UNE && isKnownNeverInfinity(LHS, Q.TLI))
+ if (Pred == FCmpInst::FCMP_UNE && isKnownNeverInfinity(LHS, Q.DL, Q.TLI))
return getTrue(RetTy);
// LHS == Inf || LHS == NaN
- if (Pred == FCmpInst::FCMP_UEQ && isKnownNeverInfinity(LHS, Q.TLI) &&
- isKnownNeverNaN(LHS, Q.TLI))
+ if (Pred == FCmpInst::FCMP_UEQ &&
+ isKnownNeverInfinity(LHS, Q.DL, Q.TLI) &&
+ isKnownNeverNaN(LHS, Q.DL, Q.TLI))
return getFalse(RetTy);
// LHS != Inf && LHS != NaN
- if (Pred == FCmpInst::FCMP_ONE && isKnownNeverInfinity(LHS, Q.TLI) &&
- isKnownNeverNaN(LHS, Q.TLI))
+ if (Pred == FCmpInst::FCMP_ONE &&
+ isKnownNeverInfinity(LHS, Q.DL, Q.TLI) &&
+ isKnownNeverNaN(LHS, Q.DL, Q.TLI))
return getTrue(RetTy);
}
if (C->isNegative() && !C->isNegZero()) {
@@ -4100,14 +4103,14 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
case FCmpInst::FCMP_UGT:
case FCmpInst::FCMP_UNE:
// (X >= 0) implies (X > C) when (C < 0)
- if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ if (CannotBeOrderedLessThanZero(LHS, Q.DL, Q.TLI))
return getTrue(RetTy);
break;
case FCmpInst::FCMP_OEQ:
case FCmpInst::FCMP_OLE:
case FCmpInst::FCMP_OLT:
// (X >= 0) implies !(X < C) when (C < 0)
- if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ if (CannotBeOrderedLessThanZero(LHS, Q.DL, Q.TLI))
return getFalse(RetTy);
break;
default:
@@ -4167,15 +4170,15 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
case FCmpInst::FCMP_ULT:
// Positive or zero X >= 0.0 --> true
// Positive or zero X < 0.0 --> false
- if ((FMF.noNaNs() || isKnownNeverNaN(LHS, Q.TLI)) &&
- CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ if ((FMF.noNaNs() || isKnownNeverNaN(LHS, Q.DL, Q.TLI)) &&
+ CannotBeOrderedLessThanZero(LHS, Q.DL, Q.TLI))
return Pred == FCmpInst::FCMP_OGE ? getTrue(RetTy) : getFalse(RetTy);
break;
case FCmpInst::FCMP_UGE:
case FCmpInst::FCMP_OLT:
// Positive or zero or nan X >= 0.0 --> true
// Positive or zero or nan X < 0.0 --> false
- if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
+ if (CannotBeOrderedLessThanZero(LHS, Q.DL, Q.TLI))
return Pred == FCmpInst::FCMP_UGE ? getTrue(RetTy) : getFalse(RetTy);
break;
default:
@@ -5629,8 +5632,10 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
return ConstantFP::getZero(Op0->getType());
// +normal number * (-)0.0 --> (-)0.0
- if (isKnownNeverInfinity(Op0, Q.TLI) && isKnownNeverNaN(Op0, Q.TLI) &&
- SignBitMustBeZero(Op0, Q.TLI))
+ // TODO: Use computeKnownFPClass
+ if (isKnownNeverInfinity(Op0, Q.DL, Q.TLI) &&
+ isKnownNeverNaN(Op0, Q.DL, Q.TLI) &&
+ SignBitMustBeZero(Op0, Q.DL, Q.TLI))
return Op1;
}
@@ -6037,7 +6042,7 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
Value *X;
switch (IID) {
case Intrinsic::fabs:
- if (SignBitMustBeZero(Op0, Q.TLI))
+ if (SignBitMustBeZero(Op0, Q.DL, Q.TLI))
return Op0;
break;
case Intrinsic::bswap:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 28b4fc454c141..1085be6986db0 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3832,9 +3832,9 @@ bool llvm::CannotBeNegativeZero(const Value *V, const TargetLibraryInfo *TLI,
/// standard ordered compare. e.g. make -0.0 olt 0.0 be true because of the sign
/// bit despite comparing equal.
static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
+ const DataLayout &DL,
const TargetLibraryInfo *TLI,
- bool SignBitOnly,
- unsigned Depth) {
+ bool SignBitOnly, unsigned Depth) {
// TODO: This function does not do the right thing when SignBitOnly is true
// and we're lowering to a hypothetical IEEE 754-compliant-but-evil platform
// which flips the sign bits of NaNs. See
@@ -3883,9 +3883,9 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
return true;
// Set SignBitOnly for RHS, because X / -0.0 is -Inf (or NaN).
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1) &&
- cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI,
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1) &&
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(1), DL, TLI,
/*SignBitOnly*/ true, Depth + 1);
case Instruction::FMul:
// X * X is always non-negative or a NaN.
@@ -3896,26 +3896,26 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
[[fallthrough]];
case Instruction::FAdd:
case Instruction::FRem:
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1) &&
- cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1) &&
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(1), DL, TLI,
+ SignBitOnly, Depth + 1);
case Instruction::Select:
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI, SignBitOnly,
- Depth + 1) &&
- cannotBeOrderedLessThanZeroImpl(I->getOperand(2), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(1), DL, TLI,
+ SignBitOnly, Depth + 1) &&
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(2), DL, TLI,
+ SignBitOnly, Depth + 1);
case Instruction::FPExt:
case Instruction::FPTrunc:
// Widening/narrowing never change sign.
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1);
case Instruction::ExtractElement:
// Look through extract element. At the moment we keep this simple and skip
// tracking the specific element. But at least we might find information
// valid for all elements of the vector.
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1);
case Instruction::Call:
const auto *CI = cast<CallInst>(I);
Intrinsic::ID IID = getIntrinsicForCallSite(*CI, TLI);
@@ -3932,7 +3932,8 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
case Intrinsic::round:
case Intrinsic::roundeven:
case Intrinsic::fptrunc_round:
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly, Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1);
case Intrinsic::maxnum: {
Value *V0 = I->getOperand(0), *V1 = I->getOperand(1);
auto isPositiveNum = [&](Value *V) {
@@ -3947,8 +3948,8 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
// -0.0 compares equal to 0.0, so if this operand is at least -0.0,
// maxnum can't be ordered-less-than-zero.
- return isKnownNeverNaN(V, TLI) &&
- cannotBeOrderedLessThanZeroImpl(V, TLI, false, Depth + 1);
+ return isKnownNeverNaN(V, DL, TLI) &&
+ cannotBeOrderedLessThanZeroImpl(V, DL, TLI, false, Depth + 1);
};
// TODO: This could be improved. We could also check that neither operand
@@ -3957,23 +3958,23 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
}
case Intrinsic::maximum:
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1) ||
- cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1) ||
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(1), DL, TLI,
+ SignBitOnly, Depth + 1);
case Intrinsic::minnum:
case Intrinsic::minimum:
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1) &&
- cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1) &&
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(1), DL, TLI,
+ SignBitOnly, Depth + 1);
case Intrinsic::exp:
case Intrinsic::exp2:
case Intrinsic::fabs:
return true;
case Intrinsic::copysign:
// Only the sign operand matters.
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI, true,
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(1), DL, TLI, true,
Depth + 1);
case Intrinsic::sqrt:
// sqrt(x) is always >= -0 or NaN. Moreover, sqrt(x) == -0 iff x == -0.
@@ -4001,33 +4002,33 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
// but we must return false if x == -0. Unfortunately we do not currently
// have a way of expressing this constraint. See details in
// https://llvm.org/bugs/show_bug.cgi?id=31702.
- return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
- Depth + 1);
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), DL, TLI,
+ SignBitOnly, Depth + 1);
case Intrinsic::fma:
case Intrinsic::fmuladd:
// x*x+y is non-negative if y is non-negative.
return I->getOperand(0) == I->getOperand(1) &&
(!SignBitOnly || cast<FPMathOperator>(I)->hasNoNaNs()) &&
- cannotBeOrderedLessThanZeroImpl(I->getOperand(2), TLI, SignBitOnly,
- Depth + 1);
+ cannotBeOrderedLessThanZeroImpl(I->getOperand(2), DL, TLI,
+ SignBitOnly, Depth + 1);
}
break;
}
return false;
}
-bool llvm::CannotBeOrderedLessThanZero(const Value *V,
+bool llvm::CannotBeOrderedLessThanZero(const Value *V, const DataLayout &DL,
const TargetLibraryInfo *TLI) {
- return cannotBeOrderedLessThanZeroImpl(V, TLI, false, 0);
+ return cannotBeOrderedLessThanZeroImpl(V, DL, TLI, false, 0);
}
-bool llvm::SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI) {
- return cannotBeOrderedLessThanZeroImpl(V, TLI, true, 0);
-}
-
-bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
- unsigned Depth) {
+bool llvm::isKnownNeverInfinity(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI, unsigned Depth,
+ AssumptionCache *AC, const Instruction *CtxI,
+ const DominatorTree *DT,
+ OptimizationRemarkEmitter *ORE,
+ bool UseInstrInfo) {
assert(V->getType()->isFPOrFPVectorTy() && "Querying for Inf on non-FP type");
// If we're told that infinities won't happen, assume they won't.
@@ -4057,8 +4058,8 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
if (auto *Inst = dyn_cast<Instruction>(V)) {
switch (Inst->getOpcode()) {
case Instruction::Select: {
- return isKnownNeverInfinity(Inst->getOperand(1), TLI, Depth + 1) &&
- isKnownNeverInfinity(Inst->getOperand(2), TLI, Depth + 1);
+ return isKnownNeverInfinity(Inst->getOperand(1), DL, TLI, Depth + 1) &&
+ isKnownNeverInfinity(Inst->getOperand(2), DL, TLI, Depth + 1);
}
case Instruction::SIToFP:
case Instruction::UIToFP: {
@@ -4077,7 +4078,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
case Instruction::FNeg:
case Instruction::FPExt: {
// Peek through to source op. If it is not infinity, this is not infinity.
- return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
+ return isKnownNeverInfinity(Inst->getOperand(0), DL, TLI, Depth + 1);
}
case Instruction::FPTrunc: {
// Need a range check.
@@ -4099,7 +4100,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
case Intrinsic::copysign:
case Intrinsic::arithmetic_fence:
case Intrinsic::trunc:
- return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
+ return isKnownNeverInfinity(Inst->getOperand(0), DL, TLI, Depth + 1);
case Intrinsic::floor:
case Intrinsic::ceil:
case Intrinsic::rint:
@@ -4109,7 +4110,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
// PPC_FP128 is a special case.
if (V->getType()->isMultiUnitFPType())
return false;
- return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
+ return isKnownNeverInfinity(Inst->getOperand(0), DL, TLI, Depth + 1);
case Intrinsic::fptrunc_round:
// Requires knowing the value range.
return false;
@@ -4117,8 +4118,8 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
case Intrinsic::maxnum:
case Intrinsic::minimum:
case Intrinsic::maximum:
- return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1) &&
- isKnownNeverInfinity(Inst->getOperand(1), TLI, Depth + 1);
+ return isKnownNeverInfinity(Inst->getOperand(0), DL, TLI, Depth + 1) &&
+ isKnownNeverInfinity(Inst->getOperand(1), DL, TLI, Depth + 1);
case Intrinsic::log:
case Intrinsic::log10:
case Intrinsic::log2:
@@ -4166,8 +4167,16 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
return false;
}
-bool llvm::isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
- unsigned Depth) {
+bool llvm::SignBitMustBeZero(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI) {
+ return cannotBeOrderedLessThanZeroImpl(V, DL, TLI, true, 0);
+}
+
+bool llvm::isKnownNeverNaN(const Value *V, const DataLayout &DL,
+ const TargetLibraryInfo *TLI, unsigned Depth,
+ AssumptionCache *AC, const Instruction *CtxI,
+ const DominatorTree *DT,
+ OptimizationRemarkEmitter *ORE, bool UseInstrInfo) {
assert(V->getType()->isFPOrFPVectorTy() && "Querying for NaN on non-FP type");
// If we're told that NaNs won't happen, assume they won't.
@@ -4200,18 +4209,18 @@ bool llvm::isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
case Instruction::FAdd:
case Instruction::FSub:
// Adding positive and negative infinity produces NaN.
- return isKnownNeverNaN(Inst->getOperand(0), TLI, Depth + 1) &&
- isKnownNeverNaN(Inst->getOperand(1), TLI, Depth + 1) &&
- (isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1) ||
- isKnownNeverInfinity(Inst->getOperand(1), TLI, Depth + 1));
+ return isKnownNeverNaN(Inst->getOperand(0), DL, TLI, Depth + 1) &&
+ isKnownNeverNaN(Inst->getOperand(1), DL, TLI, Depth + 1) &&
+ (isKnownNeverInfinity(Inst->getOperand(0), DL, TLI, Depth + 1) ||
+ isKnownNeverInfinity(Inst->getOperand(1), DL, TLI, Depth + 1));
case Instruction::FMul:
// Zero multiplied with infinity produces NaN.
// FIXME: If neither side can be zero fmul never produces NaN.
- return isKnownNeverNaN(Inst->getOperand(0), TLI, Depth + 1) &&
- isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1) &&
- isKnownNeverNaN(Inst->getOperand(1), TLI, Depth + 1) &&
- isKnownNeverInfinity(Inst->getOperand(1), TLI, Depth + 1);
+ return isKnownNeverNaN(Inst->getOperand(0), DL, TLI, Depth + 1) &&
+ isKnownNeverInfinity(Inst->getOperand(0), DL, TLI, Depth + 1) &&
+ isKnownNeverNaN(Inst->getOperand(1), DL, TLI, Depth + 1) &&
+ isKnownNeverInfinity(Inst->getOperand(1), DL, TLI, Depth + 1);
case Instruction::FDiv:
case Instruction::FRem:
@@ -4219,8 +4228,8 @@ bool llvm::isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
return false;
case Instruction::Select: {
- return isKnownNeverNaN(Inst->getOperand(1), TLI, Depth + 1) &&
- isKnownNeverNaN(Inst->getOperand(2), TLI, Depth + 1);
+ return isKnownNeverNaN(Inst->getOperand(1), DL, TLI, Depth + 1) &&
+ isKnownNeverNaN(Inst->getOperand(2), DL, TLI, Depth + 1);
}
case Instruction::SIToFP:
case Instruction::UIToFP:
@@ -4228,7 +4237,7 @@ bool llvm::isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
case Instruction::FPTrunc:
case Instruction::FPExt:
case Instruction::FNeg:
- return isKnownNeverNaN(Inst->getOperand(0), TLI, Depth + 1);
+ return isKnownNeverNaN(Inst->getOperand(0), DL, TLI, Depth + 1);
default:
break;
}
@@ -4249,15 +4258,15 @@ bool llvm::isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
case Intrinsic::round:
case Intrinsic::roundeven:
case Intrinsic::arithmetic_fence:
- return isKnownNeverNaN(II->getArgOperand(0), TLI, Depth + 1);
+ return isKnownNeverNaN(II->getArgOperand(0), DL, TLI, Depth + 1);
case Intrinsic::sqrt:
- return isKnownNeverNaN(II->getArgOperand(0), TLI, Depth + 1) &&
- CannotBeOrderedLessThanZero(II->getArgOperand(0), TLI);
+ return isKnownNeverNaN(II->getArgOperand(0), DL, TLI, Depth + 1) &&
+ CannotBeOrderedLessThanZero(II->getArgOperand(0), DL, TLI);
case Intrinsic::minnum:
case Intrinsic::maxnum:
// If either operand is not NaN, the result is not NaN.
- return isKnownNeverNaN(II->getArgOperand(0), TLI, Depth + 1) ||
- isKnownNeverNaN(II->getArgOperand(1), TLI, Depth + 1);
+ return isKnownNeverNaN(II->getArgOperand(0), DL, TLI, Depth + 1) ||
+ isKnownNeverNaN(II->getArgOperand(1), DL, TLI, Depth + 1);
default:
return false;
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 9b9cec6581b3b..0fac9c8a6df6b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -499,7 +499,8 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
}
// fp_class (nnan x), qnan|snan|other -> fp_class (nnan x), other
- if ((Mask & fcNan) && isKnownNeverNaN(Src0, &IC.getTargetLibraryInfo())) {
+ if ((Mask & fcNan) &&
+ isKnownNeverNaN(Src0, IC.getDataLayout(), &IC.getTargetLibraryInfo())) {
return IC.replaceOperand(
II, 1, ConstantInt::get(Src1->getType(), Mask & ~fcNan));
}
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index 1fd1567caec24..f7b114b53a843 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -423,7 +423,8 @@ static bool foldSqrt(Instruction &I, TargetTransformInfo &TTI,
Type *Ty = Call->getType();
Value *Arg = Call->getArgOperand(0);
if (TTI.haveFastSqrt(Ty) &&
- (Call->hasNoNaNs() || CannotBeOrderedLessThanZero(Arg, &TLI))) {
+ (Call->hasNoNaNs() ||
+ CannotBeOrderedLessThanZero(Arg, M->getDataLayout(), &TLI))) {
IRBuilder<> Builder(&I);
IRBuilderBase::FastMathFlagGuard Guard(Builder);
Builder.setFastMathFlags(Call->getFastMathFlags());
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 73c0e35c1ac0c..c2ef6f8b79101 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2204,7 +2204,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
case Intrinsic::copysign: {
Value *Mag = II->getArgOperand(0), *Sign = II->getArgOperand(1);
- if (SignBitMustBeZero(Sign, &TLI)) {
+ if (SignBitMustBeZero(Sign, DL, &TLI)) {
// If we know that the sign argument is positive, reduce to FABS:
// copysign Mag, +Sign --> fabs Mag
Value *Fabs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, Mag, II);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 1815fc858c679..d5b2aa670c603 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -7152,10 +7152,10 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
// If we're just checking for a NaN (ORD/UNO) and have a non-NaN operand,
// then canonicalize the operand to 0.0.
if (Pred == CmpInst::FCMP_ORD || Pred == CmpInst::FCMP_UNO) {
- if (!match(Op0, m_PosZeroFP()) && isKnownNeverNaN(Op0, &TLI))
+ if (!match(Op0, m_PosZeroFP()) && isKnownNeverNaN(Op0, DL, &TLI))
return replaceOperand(I, 0, ConstantFP::getZero(OpType));
- if (!match(Op1, m_PosZeroFP()) && isKnownNeverNaN(Op1, &TLI))
+ if (!match(Op1, m_PosZeroFP()) && isKnownNeverNaN(Op1, DL, &TLI))
return replaceOperand(I, 1, ConstantFP::getZero(OpType));
}
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index d83fbc100c4fc..190b17f177a9a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2179,7 +2179,7 @@ Value *LibCallSimplifier::replacePowWithSqrt(CallInst *Pow, IRBuilderBase &B) {
// pow(-Inf, 0.5) is optionally required to have a result of +Inf (not setting
// errno), but sqrt(-Inf) is required by various standards to set errno.
if (!Pow->doesNotAccessMemory() && !Pow->hasNoInfs() &&
- !isKnownNeverInfinity(Base, TLI))
+ !isKnownNeverInfinity(Base, DL, TLI))
return nullptr;
Sqrt = getSqrtCall(Base, AttributeList(), Pow->doesNotAccessMemory(), Mod, B,
More information about the llvm-commits
mailing list