https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107608

--- Comment #16 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Created attachment 54224
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54224&action=edit
untested patch

Perhaps this would work.  It solves the testcase, though I think we should
probably audit the operators that don't use the generic
range_operator_float::fold_range to make sure they're not doing anything silly.

Note that we could add similar code whenever we drop to a NAN like const_binop
does:

      /* Don't constant fold this floating point operation if
         both operands are not NaN but the result is NaN, and
         flag_trapping_math.  Such operations should raise an
         invalid operation exception.  */
      if (flag_trapping_math
          && MODE_HAS_NANS (mode)
          && REAL_VALUE_ISNAN (result)
          && !REAL_VALUE_ISNAN (d1)
          && !REAL_VALUE_ISNAN (d2))
        return NULL_TREE;

I avoided doing so because an frange of NAN does not count as a singleton so it
should never be propagated.  If this is a problem, I could add a similar tweak.

What do y'all think?

Reply via email to