+
+ // If lhs isn't NAN, then neither operand could be NAN,
+ // even if the reverse operation does introduce a maybe_nan.
+ if (!lhs.maybe_isnan ())
+ r.clear_nan ();
+ // If lhs is a maybe or known NAN, the operand could be
+ // NAN.
+ else
+ r.update_nan ();
+ return true;
+}
+
class foperator_plus : public range_operator_float
{
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
+public:
+ virtual bool op1_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op2,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ if (lhs.undefined_p ())
+ return false;
+ range_op_handler minus (MINUS_EXPR, type);
+ if (!minus)
+ return false;
+ return float_binary_op_range_finish (minus.fold_range (r, type, lhs, op2),
+ r, type, lhs);
+ } > + virtual bool op2_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op1,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ return op1_range (r, type, lhs, op1);
+ }
+private:
void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
tree type,
const REAL_VALUE_TYPE &lh_lb,
@@ -1888,6 +1944,31 @@ class foperator_plus : public range_oper
class foperator_minus : public range_operator_float
{
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
+public:
+ virtual bool op1_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op2,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ if (lhs.undefined_p ())
+ return false;
+ return float_binary_op_range_finish (fop_plus.fold_range (r, type, lhs,
+ op2),
+ r, type, lhs);
+ }
+ virtual bool op2_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op1,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ if (lhs.undefined_p ())
+ return false;
+ return float_binary_op_range_finish (fold_range (r, type, op1, lhs),
+ r, type, lhs);
+ }
+private:
void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
tree type,
const REAL_VALUE_TYPE &lh_lb,
@@ -2031,6 +2112,30 @@ protected:
class foperator_mult : public foperator_mult_div_base
{
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
+public:
+ virtual bool op1_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op2,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ if (lhs.undefined_p ())
+ return false;
+ range_op_handler rdiv (RDIV_EXPR, type);
+ if (!rdiv)
+ return false;
+ return float_binary_op_range_finish (rdiv.fold_range (r, type, lhs, op2),
+ r, type, lhs);
+ }
+ virtual bool op2_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op1,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ return op1_range (r, type, lhs, op1);
+ }
+private:
void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
tree type,
const REAL_VALUE_TYPE &lh_lb,
@@ -2138,6 +2243,31 @@ class foperator_mult : public foperator_
class foperator_div : public foperator_mult_div_base
{
+ using range_operator_float::op1_range;
+ using range_operator_float::op2_range;
+public:
+ virtual bool op1_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op2,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ if (lhs.undefined_p ())
+ return false;
+ return float_binary_op_range_finish (fop_mult.fold_range (r, type, lhs,
+ op2),
+ r, type, lhs);
+ }
+ virtual bool op2_range (frange &r, tree type,
+ const frange &lhs,
+ const frange &op1,
+ relation_trio = TRIO_VARYING) const final override
+ {
+ if (lhs.undefined_p ())
+ return false;
+ return float_binary_op_range_finish (fold_range (r, type, op1, lhs),
+ r, type, lhs);
+ }
+private:
void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
tree type,
const REAL_VALUE_TYPE &lh_lb,
--- gcc/testsuite/gcc.c-torture/execute/ieee/inf-4.c.jj 2022-11-11
12:44:57.615274471 +0100
+++ gcc/testsuite/gcc.c-torture/execute/ieee/inf-4.c 2022-11-11
12:44:13.351879222 +0100
@@ -0,0 +1,26 @@
+__attribute__((noipa)) int
+foo (double a, double b)
+{
+ double c = a - b;
+ if (!__builtin_isfinite (c))
+ {
+ if (__builtin_isnan (c))
+ {
+ if (!__builtin_isnan (a) && !__builtin_isnan (b))
+ return 1;
+ }
+ else if (__builtin_isfinite (a) && __builtin_isfinite (b))
+ return 2;
+ }
+ else if (c == 0 && a != b)
+ return 3;
+ return 4;
+}
+
+int
+main ()
+{
+ double a = __builtin_inf ();
+ if (foo (a, a) != 1)
+ __builtin_abort ();
+}
Jakub