@@ -7324,17 +7324,14 @@ Instruction *InstCombinerImpl::foldFCmpIntToFPConst(FCmpInst &I,
7324
7324
}
7325
7325
7326
7326
// Okay, now we know that the FP constant fits in the range [SMIN, SMAX] or
7327
- // [0, UMAX], but it may still be fractional. See if it is fractional by
7328
- // casting the FP value to the integer value and back, checking for equality .
7327
+ // [0, UMAX], but it may still be fractional. Check whether this is the case
7328
+ // using the IsExact flag .
7329
7329
// Don't do this for zero, because -0.0 is not fractional.
7330
- Constant * RHSInt = LHSUnsigned
7331
- ? ConstantExpr::getFPToUI (RHSC, IntTy)
7332
- : ConstantExpr::getFPToSI (RHSC, IntTy );
7330
+ APSInt RHSInt (IntWidth, LHSUnsigned);
7331
+ bool IsExact;
7332
+ RHS. convertToInteger (RHSInt, APFloat::rmTowardZero, &IsExact );
7333
7333
if (!RHS.isZero ()) {
7334
- bool Equal = LHSUnsigned
7335
- ? ConstantExpr::getUIToFP (RHSInt, RHSC->getType ()) == RHSC
7336
- : ConstantExpr::getSIToFP (RHSInt, RHSC->getType ()) == RHSC;
7337
- if (!Equal) {
7334
+ if (!IsExact) {
7338
7335
// If we had a comparison against a fractional value, we have to adjust
7339
7336
// the compare predicate and sometimes the value. RHSC is rounded towards
7340
7337
// zero at this point.
@@ -7400,7 +7397,7 @@ Instruction *InstCombinerImpl::foldFCmpIntToFPConst(FCmpInst &I,
7400
7397
7401
7398
// Lower this FP comparison into an appropriate integer version of the
7402
7399
// comparison.
7403
- return new ICmpInst (Pred, LHSI->getOperand (0 ), RHSInt);
7400
+ return new ICmpInst (Pred, LHSI->getOperand (0 ), Builder. getInt ( RHSInt) );
7404
7401
}
7405
7402
7406
7403
// / Fold (C / X) < 0.0 --> X < 0.0 if possible. Swap predicate if necessary.
0 commit comments