http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57994

--- Comment #19 from Paolo Carlini <paolo.carlini at oracle dot com> ---
If I change fold_builtin_logarithm to pass a true as last argument to
do_mpfr_arg1 (thus 0 is accepted) and do_mpfr_ckconv to accept a folded result
which is infinity, things finally work. Patchlet below. Note however, that I
also need -O1 otherwise, at -O0, we don't try to propagate the constant num and
mpfr isn't used, we again have a library call which returns -nan.

Index: builtins.c
===================================================================
--- builtins.c    (revision 204005)
+++ builtins.c    (working copy)
@@ -8191,7 +8191,7 @@ fold_builtin_logarithm (location_t loc, tree fndec
       const enum built_in_function fcode = builtin_mathfn_code (arg);

       /* Calculate the result when the argument is a constant.  */
-      if ((res = do_mpfr_arg1 (arg, type, func, &dconst0, NULL, false)))
+      if ((res = do_mpfr_arg1 (arg, type, func, &dconst0, NULL, true)))
     return res;

       /* Special case, optimize logN(expN(x)) = x.  */
@@ -13527,7 +13527,7 @@ do_mpfr_ckconv (mpfr_srcptr m, tree type, int inex
   /* Proceed iff we get a normal number, i.e. not NaN or Inf and no
      overflow/underflow occurred.  If -frounding-math, proceed iff the
      result of calling FUNC was exact.  */
-  if (mpfr_number_p (m) && !mpfr_overflow_p () && !mpfr_underflow_p ()
+  if (!mpfr_nan_p (m) && !mpfr_overflow_p () && !mpfr_underflow_p ()
       && (!flag_rounding_math || !inexact))
     {
       REAL_VALUE_TYPE rr;
@@ -13537,7 +13537,7 @@ do_mpfr_ckconv (mpfr_srcptr m, tree type, int inex
      check for overflow/underflow.  If the REAL_VALUE_TYPE is zero
      but the mpft_t is not, then we underflowed in the
      conversion.  */
-      if (real_isfinite (&rr)
+      if (!real_isnan (&rr)
       && (rr.cl == rvc_zero) == (mpfr_zero_p (m) != 0))
         {
       REAL_VALUE_TYPE rmode;
@@ -13623,7 +13623,7 @@ do_mpfr_arg1 (tree arg, tree type, int (*func)(mpf
     {
       const REAL_VALUE_TYPE *const ra = &TREE_REAL_CST (arg);

-      if (real_isfinite (ra)
+      if (!real_isnan (ra)
       && (!min || real_compare (inclusive ? GE_EXPR: GT_EXPR , ra, min))
       && (!max || real_compare (inclusive ? LE_EXPR: LT_EXPR , ra, max)))
         {

Reply via email to