forked from OSchip/llvm-project
[APFloat] Make use of new overloaded comparison operators. NFC.
Reviewers: ekatz, spatel, jfb, tlively, craig.topper, RKSimon, nikic, scanon Subscribers: arsenm, jvesely, nhaehnle, hiraditya, dexonsmith, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75744
This commit is contained in:
parent
6c61edcbab
commit
11d1573bb6
|
@ -1277,7 +1277,7 @@ inline APFloat minnum(const APFloat &A, const APFloat &B) {
|
|||
return B;
|
||||
if (B.isNaN())
|
||||
return A;
|
||||
return (B.compare(A) == APFloat::cmpLessThan) ? B : A;
|
||||
return B < A ? B : A;
|
||||
}
|
||||
|
||||
/// Implements IEEE maxNum semantics. Returns the larger of the 2 arguments if
|
||||
|
@ -1288,7 +1288,7 @@ inline APFloat maxnum(const APFloat &A, const APFloat &B) {
|
|||
return B;
|
||||
if (B.isNaN())
|
||||
return A;
|
||||
return (A.compare(B) == APFloat::cmpLessThan) ? B : A;
|
||||
return A < B ? B : A;
|
||||
}
|
||||
|
||||
/// Implements IEEE 754-2018 minimum semantics. Returns the smaller of 2
|
||||
|
@ -1301,7 +1301,7 @@ inline APFloat minimum(const APFloat &A, const APFloat &B) {
|
|||
return B;
|
||||
if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
|
||||
return A.isNegative() ? A : B;
|
||||
return (B.compare(A) == APFloat::cmpLessThan) ? B : A;
|
||||
return B < A ? B : A;
|
||||
}
|
||||
|
||||
/// Implements IEEE 754-2018 maximum semantics. Returns the larger of 2
|
||||
|
@ -1314,7 +1314,7 @@ inline APFloat maximum(const APFloat &A, const APFloat &B) {
|
|||
return B;
|
||||
if (A.isZero() && B.isZero() && (A.isNegative() != B.isNegative()))
|
||||
return A.isNegative() ? B : A;
|
||||
return (A.compare(B) == APFloat::cmpLessThan) ? B : A;
|
||||
return A < B ? B : A;
|
||||
}
|
||||
|
||||
} // namespace llvm
|
||||
|
|
|
@ -2555,11 +2555,9 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
|
|||
case LibFunc_expf:
|
||||
// FIXME: These boundaries are slightly conservative.
|
||||
if (OpC->getType()->isDoubleTy())
|
||||
return Op.compare(APFloat(-745.0)) != APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(709.0)) != APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(-745.0) || Op > APFloat(709.0));
|
||||
if (OpC->getType()->isFloatTy())
|
||||
return Op.compare(APFloat(-103.0f)) != APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(88.0f)) != APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(-103.0f) || Op > APFloat(88.0f));
|
||||
break;
|
||||
|
||||
case LibFunc_exp2l:
|
||||
|
@ -2567,11 +2565,9 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
|
|||
case LibFunc_exp2f:
|
||||
// FIXME: These boundaries are slightly conservative.
|
||||
if (OpC->getType()->isDoubleTy())
|
||||
return Op.compare(APFloat(-1074.0)) != APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(1023.0)) != APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(-1074.0) || Op > APFloat(1023.0));
|
||||
if (OpC->getType()->isFloatTy())
|
||||
return Op.compare(APFloat(-149.0f)) != APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(127.0f)) != APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(-149.0f) || Op > APFloat(127.0f));
|
||||
break;
|
||||
|
||||
case LibFunc_sinl:
|
||||
|
@ -2601,10 +2597,8 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
|
|||
case LibFunc_acosl:
|
||||
case LibFunc_acos:
|
||||
case LibFunc_acosf:
|
||||
return Op.compare(APFloat(Op.getSemantics(), "-1")) !=
|
||||
APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(Op.getSemantics(), "1")) !=
|
||||
APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(Op.getSemantics(), "-1") ||
|
||||
Op > APFloat(Op.getSemantics(), "1"));
|
||||
|
||||
case LibFunc_sinh:
|
||||
case LibFunc_cosh:
|
||||
|
@ -2614,11 +2608,9 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
|
|||
case LibFunc_coshl:
|
||||
// FIXME: These boundaries are slightly conservative.
|
||||
if (OpC->getType()->isDoubleTy())
|
||||
return Op.compare(APFloat(-710.0)) != APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(710.0)) != APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(-710.0) || Op > APFloat(710.0));
|
||||
if (OpC->getType()->isFloatTy())
|
||||
return Op.compare(APFloat(-89.0f)) != APFloat::cmpLessThan &&
|
||||
Op.compare(APFloat(89.0f)) != APFloat::cmpGreaterThan;
|
||||
return !(Op < APFloat(-89.0f) || Op > APFloat(89.0f));
|
||||
break;
|
||||
|
||||
case LibFunc_sqrtl:
|
||||
|
|
|
@ -3617,9 +3617,9 @@ static Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
|
|||
// Check comparison of [minnum/maxnum with constant] with other constant.
|
||||
const APFloat *C2;
|
||||
if ((match(LHS, m_Intrinsic<Intrinsic::minnum>(m_Value(), m_APFloat(C2))) &&
|
||||
C2->compare(*C) == APFloat::cmpLessThan) ||
|
||||
*C2 < *C) ||
|
||||
(match(LHS, m_Intrinsic<Intrinsic::maxnum>(m_Value(), m_APFloat(C2))) &&
|
||||
C2->compare(*C) == APFloat::cmpGreaterThan)) {
|
||||
*C2 > *C)) {
|
||||
bool IsMaxNum =
|
||||
cast<IntrinsicInst>(LHS)->getIntrinsicID() == Intrinsic::maxnum;
|
||||
// The ordered relationship and minnum/maxnum guarantee that we do not
|
||||
|
|
|
@ -4886,7 +4886,7 @@ static SelectPatternResult matchFastFloatClamp(CmpInst::Predicate Pred,
|
|||
if (match(FalseVal,
|
||||
m_CombineOr(m_OrdFMin(m_Specific(CmpLHS), m_APFloat(FC2)),
|
||||
m_UnordFMin(m_Specific(CmpLHS), m_APFloat(FC2)))) &&
|
||||
FC1->compare(*FC2) == APFloat::cmpResult::cmpLessThan)
|
||||
*FC1 < *FC2)
|
||||
return {SPF_FMAXNUM, SPNB_RETURNS_ANY, false};
|
||||
break;
|
||||
case CmpInst::FCMP_OGT:
|
||||
|
@ -4896,7 +4896,7 @@ static SelectPatternResult matchFastFloatClamp(CmpInst::Predicate Pred,
|
|||
if (match(FalseVal,
|
||||
m_CombineOr(m_OrdFMax(m_Specific(CmpLHS), m_APFloat(FC2)),
|
||||
m_UnordFMax(m_Specific(CmpLHS), m_APFloat(FC2)))) &&
|
||||
FC1->compare(*FC2) == APFloat::cmpResult::cmpGreaterThan)
|
||||
*FC1 > *FC2)
|
||||
return {SPF_FMINNUM, SPNB_RETURNS_ANY, false};
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -934,7 +934,7 @@ MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {
|
|||
|
||||
APFloat AVal = mdconst::extract<ConstantFP>(A->getOperand(0))->getValueAPF();
|
||||
APFloat BVal = mdconst::extract<ConstantFP>(B->getOperand(0))->getValueAPF();
|
||||
if (AVal.compare(BVal) == APFloat::cmpLessThan)
|
||||
if (AVal < BVal)
|
||||
return A;
|
||||
return B;
|
||||
}
|
||||
|
|
|
@ -4588,7 +4588,7 @@ bool DoubleAPFloat::isDenormal() const {
|
|||
return getCategory() == fcNormal &&
|
||||
(Floats[0].isDenormal() || Floats[1].isDenormal() ||
|
||||
// (double)(Hi + Lo) == Hi defines a normal number.
|
||||
Floats[0].compare(Floats[0] + Floats[1]) != cmpEqual);
|
||||
Floats[0] != Floats[0] + Floats[1]);
|
||||
}
|
||||
|
||||
bool DoubleAPFloat::isSmallest() const {
|
||||
|
|
|
@ -8979,8 +8979,7 @@ SDValue SITargetLowering::performFPMed3ImmCombine(SelectionDAG &DAG,
|
|||
return SDValue();
|
||||
|
||||
// Ordered >= (although NaN inputs should have folded away by now).
|
||||
APFloat::cmpResult Cmp = K0->getValueAPF().compare(K1->getValueAPF());
|
||||
if (Cmp == APFloat::cmpGreaterThan)
|
||||
if (K0->getValueAPF() > K1->getValueAPF())
|
||||
return SDValue();
|
||||
|
||||
const MachineFunction &MF = DAG.getMachineFunction();
|
||||
|
@ -9852,16 +9851,13 @@ SDValue SITargetLowering::performClampCombine(SDNode *N,
|
|||
const MachineFunction &MF = DCI.DAG.getMachineFunction();
|
||||
const APFloat &F = CSrc->getValueAPF();
|
||||
APFloat Zero = APFloat::getZero(F.getSemantics());
|
||||
APFloat::cmpResult Cmp0 = F.compare(Zero);
|
||||
if (Cmp0 == APFloat::cmpLessThan ||
|
||||
(Cmp0 == APFloat::cmpUnordered &&
|
||||
MF.getInfo<SIMachineFunctionInfo>()->getMode().DX10Clamp)) {
|
||||
if (F < Zero ||
|
||||
(F.isNaN() && MF.getInfo<SIMachineFunctionInfo>()->getMode().DX10Clamp)) {
|
||||
return DCI.DAG.getConstantFP(Zero, SDLoc(N), N->getValueType(0));
|
||||
}
|
||||
|
||||
APFloat One(F.getSemantics(), "1.0");
|
||||
APFloat::cmpResult Cmp1 = F.compare(One);
|
||||
if (Cmp1 == APFloat::cmpGreaterThan)
|
||||
if (F > One)
|
||||
return DCI.DAG.getConstantFP(One, SDLoc(N), N->getValueType(0));
|
||||
|
||||
return SDValue(CSrc, 0);
|
||||
|
|
|
@ -5678,7 +5678,7 @@ Instruction *InstCombiner::foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
|
|||
// TODO: Can never be -0.0 and other non-representable values
|
||||
APFloat RHSRoundInt(RHS);
|
||||
RHSRoundInt.roundToIntegral(APFloat::rmNearestTiesToEven);
|
||||
if (RHS.compare(RHSRoundInt) != APFloat::cmpEqual) {
|
||||
if (RHS != RHSRoundInt) {
|
||||
if (P == FCmpInst::FCMP_OEQ || P == FCmpInst::FCMP_UEQ)
|
||||
return replaceInstUsesWith(I, Builder.getFalse());
|
||||
|
||||
|
@ -5766,7 +5766,7 @@ Instruction *InstCombiner::foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
|
|||
APFloat SMax(RHS.getSemantics());
|
||||
SMax.convertFromAPInt(APInt::getSignedMaxValue(IntWidth), true,
|
||||
APFloat::rmNearestTiesToEven);
|
||||
if (SMax.compare(RHS) == APFloat::cmpLessThan) { // smax < 13123.0
|
||||
if (SMax < RHS) { // smax < 13123.0
|
||||
if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SLT ||
|
||||
Pred == ICmpInst::ICMP_SLE)
|
||||
return replaceInstUsesWith(I, Builder.getTrue());
|
||||
|
@ -5778,7 +5778,7 @@ Instruction *InstCombiner::foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
|
|||
APFloat UMax(RHS.getSemantics());
|
||||
UMax.convertFromAPInt(APInt::getMaxValue(IntWidth), false,
|
||||
APFloat::rmNearestTiesToEven);
|
||||
if (UMax.compare(RHS) == APFloat::cmpLessThan) { // umax < 13123.0
|
||||
if (UMax < RHS) { // umax < 13123.0
|
||||
if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_ULT ||
|
||||
Pred == ICmpInst::ICMP_ULE)
|
||||
return replaceInstUsesWith(I, Builder.getTrue());
|
||||
|
@ -5791,7 +5791,7 @@ Instruction *InstCombiner::foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
|
|||
APFloat SMin(RHS.getSemantics());
|
||||
SMin.convertFromAPInt(APInt::getSignedMinValue(IntWidth), true,
|
||||
APFloat::rmNearestTiesToEven);
|
||||
if (SMin.compare(RHS) == APFloat::cmpGreaterThan) { // smin > 12312.0
|
||||
if (SMin > RHS) { // smin > 12312.0
|
||||
if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SGT ||
|
||||
Pred == ICmpInst::ICMP_SGE)
|
||||
return replaceInstUsesWith(I, Builder.getTrue());
|
||||
|
@ -5802,7 +5802,7 @@ Instruction *InstCombiner::foldFCmpIntToFPConst(FCmpInst &I, Instruction *LHSI,
|
|||
APFloat UMin(RHS.getSemantics());
|
||||
UMin.convertFromAPInt(APInt::getMinValue(IntWidth), false,
|
||||
APFloat::rmNearestTiesToEven);
|
||||
if (UMin.compare(RHS) == APFloat::cmpGreaterThan) { // umin > 12312.0
|
||||
if (UMin > RHS) { // umin > 12312.0
|
||||
if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_UGT ||
|
||||
Pred == ICmpInst::ICMP_UGE)
|
||||
return replaceInstUsesWith(I, Builder.getTrue());
|
||||
|
@ -6143,8 +6143,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
|
|||
APFloat Fabs = TruncC;
|
||||
Fabs.clearSign();
|
||||
if (!Lossy &&
|
||||
((Fabs.compare(APFloat::getSmallestNormalized(FPSem)) !=
|
||||
APFloat::cmpLessThan) || Fabs.isZero())) {
|
||||
(!(Fabs < APFloat::getSmallestNormalized(FPSem)) || Fabs.isZero())) {
|
||||
Constant *NewC = ConstantFP::get(X->getType(), TruncC);
|
||||
return new FCmpInst(Pred, X, NewC, "", &I);
|
||||
}
|
||||
|
|
|
@ -327,7 +327,7 @@ void Float2IntPass::walkForwards() {
|
|||
|
||||
APFloat NewF = F;
|
||||
auto Res = NewF.roundToIntegral(APFloat::rmNearestTiesToEven);
|
||||
if (Res != APFloat::opOK || NewF.compare(F) != APFloat::cmpEqual) {
|
||||
if (Res != APFloat::opOK || NewF != F) {
|
||||
seen(I, badRange());
|
||||
Abort = true;
|
||||
break;
|
||||
|
|
|
@ -1076,7 +1076,7 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor) {
|
|||
const APFloat &F1 = FC1->getValueAPF();
|
||||
APFloat F2(FC2->getValueAPF());
|
||||
F2.changeSign();
|
||||
if (F1.compare(F2) == APFloat::cmpEqual) {
|
||||
if (F1 == F2) {
|
||||
FoundFactor = NeedsNegate = true;
|
||||
Factors.erase(Factors.begin() + i);
|
||||
break;
|
||||
|
|
|
@ -1745,7 +1745,7 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilderBase &B) {
|
|||
// be different) and it should also consider optimizing for size.
|
||||
APFloat LimF(ExpoF->getSemantics(), 33),
|
||||
ExpoA(abs(*ExpoF));
|
||||
if (ExpoA.compare(LimF) == APFloat::cmpLessThan) {
|
||||
if (ExpoA < LimF) {
|
||||
// This transformation applies to integer or integer+0.5 exponents only.
|
||||
// For integer+0.5, we create a sqrt(Base) call.
|
||||
Value *Sqrt = nullptr;
|
||||
|
|
Loading…
Reference in New Issue