Updated patch according to your comment (tabs are not pasted here). Cong
Index: gcc/convert.c =================================================================== --- gcc/convert.c (revision 201891) +++ gcc/convert.c (working copy) @@ -135,16 +135,40 @@ convert_to_real (tree type, tree expr) CASE_MATHFN (COS) CASE_MATHFN (ERF) CASE_MATHFN (ERFC) - CASE_MATHFN (FABS) CASE_MATHFN (LOG) CASE_MATHFN (LOG10) CASE_MATHFN (LOG2) CASE_MATHFN (LOG1P) - CASE_MATHFN (LOGB) CASE_MATHFN (SIN) - CASE_MATHFN (SQRT) CASE_MATHFN (TAN) CASE_MATHFN (TANH) + CASE_MATHFN (SQRT) + + /* The above functions (except sqrt) are not safe to do this conversion. */ + if (!flag_unsafe_math_optimizations) + { + /* sqrtl?(T1) could be safely converted into sqrtf?(T2) only if + p1 >= p2*2+2, where p1 and p2 are precisions of T1 and T2. + For example, on x86 the conversion from float(sqrt((double)f) to + sqrtf(f) is safe where f has the type float, since float has 23 bits + precision and double has 52 bits precision, and 52 > 23*2+2. + However, the conversion from double(sqrtl((long double)d) to + sqrt(d) is unsafe where d has the type double. This is because + long double has 63 bits precision and then 63 < 52*2+2. */ + if ((fcode == BUILT_IN_SQRT || fcode == BUILT_IN_SQRTL)) + { + int p1 = REAL_MODE_FORMAT (TYPE_MODE (type))->p; + int p2 = (fcode == BUILT_IN_SQRTL) ? + REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node))->p : + REAL_MODE_FORMAT (TYPE_MODE (double_type_node))->p; + if (p2 < p1 * 2 + 2) + break; + } + else + break; + } + CASE_MATHFN (FABS) + CASE_MATHFN (LOGB) #undef CASE_MATHFN { tree arg0 = strip_float_extensions (CALL_EXPR_ARG (expr, 0)); Index: gcc/testsuite/gcc.c-torture/execute/20030125-1.c =================================================================== --- gcc/testsuite/gcc.c-torture/execute/20030125-1.c (revision 201891) +++ gcc/testsuite/gcc.c-torture/execute/20030125-1.c (working copy) @@ -44,11 +44,11 @@ __attribute__ ((noinline)) double sin(double a) { - abort (); + return a; } __attribute__ ((noinline)) float sinf(float a) { - return a; + abort (); } On Wed, Sep 4, 2013 at 2:21 PM, Xinliang David Li <davi...@google.com> wrote: > On Wed, Sep 4, 2013 at 1:59 PM, Joseph S. Myers <jos...@codesourcery.com> > wrote: >> On Wed, 4 Sep 2013, Cong Hou wrote: >> >>> I have made a new patch according to your comments. I found several >>> references saying that the precision 2p+2 is OK for the sqrt >>> conversion (one here: >>> http://www.cs.berkeley.edu/~fateman/generic/algorithms.pdf). The new >>> patch is pasted as below. >> >> This patch submission still fails to pay attention to various of my >> comments. >> > > If you can provide inlined comments in the patch, that will be more > useful and productive. > > thanks, > > David > > >> -- >> Joseph S. Myers >> jos...@codesourcery.com