diff options
author | Cong Hou <congh@google.com> | 2013-10-24 14:10:38 -0400 |
---|---|---|
committer | Cong Hou <congh@gcc.gnu.org> | 2013-10-24 14:10:38 -0400 |
commit | 247dbcf4ab40703cb68ed7c7c593493ee0d7ec80 (patch) | |
tree | 5fa5785d8100cd687a134740afd7ed94acb90bea | |
parent | 51ce05475cc79a06001eae1163e719f570c7a9a9 (diff) | |
download | gcc-247dbcf4ab40703cb68ed7c7c593493ee0d7ec80.zip gcc-247dbcf4ab40703cb68ed7c7c593493ee0d7ec80.tar.gz gcc-247dbcf4ab40703cb68ed7c7c593493ee0d7ec80.tar.bz2 |
convert.c (convert_to_real): Guard those unsafe math function convertions with flag_unsafe_math_optimizations.
2013-10-24 Cong Hou <congh@google.com>
* convert.c (convert_to_real): Guard those unsafe math function
convertions with flag_unsafe_math_optimizations. Handle sqrt()
specially.
2013-10-24 Cong Hou <congh@google.com>
* gcc.c-torture/execute/20030125-1.c: Update.
From-SVN: r204028
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/convert.c | 42 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/20030125-1.c | 4 |
4 files changed, 50 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index eb381b4..4731f1c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-10-24 Cong Hou <congh@google.com> + + * convert.c (convert_to_real): Guard those unsafe math function + convertions with flag_unsafe_math_optimizations. Handle sqrt() + specially. + 2013-10-24 Markus Trippelsdorf <markus@trippelsdorf.de> PR ipa/58712 diff --git a/gcc/convert.c b/gcc/convert.c index b07f0ef..a2f2a33 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -135,16 +135,19 @@ 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) + /* The above functions are not safe to do this conversion. */ + if (!flag_unsafe_math_optimizations) + break; + CASE_MATHFN (SQRT) + CASE_MATHFN (FABS) + CASE_MATHFN (LOGB) #undef CASE_MATHFN { tree arg0 = strip_float_extensions (CALL_EXPR_ARG (expr, 0)); @@ -155,13 +158,44 @@ convert_to_real (tree type, tree expr) if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type)) newtype = TREE_TYPE (arg0); + /* We consider to convert + + (T1) sqrtT2 ((T2) exprT3) + to + (T1) sqrtT4 ((T4) exprT3) + + , where T1 is TYPE, T2 is ITYPE, T3 is TREE_TYPE (ARG0), + and T4 is NEWTYPE. All those types are of floating point types. + T4 (NEWTYPE) should be narrower than T2 (ITYPE). This conversion + is safe only if P1 >= P2*2+2, where P1 and P2 are precisions of + T2 and T4. See the following URL for a reference: + http://stackoverflow.com/questions/9235456/determining- + floating-point-square-root + */ + if ((fcode == BUILT_IN_SQRT || fcode == BUILT_IN_SQRTL) + && !flag_unsafe_math_optimizations) + { + /* The following conversion is unsafe even the precision condition + below is satisfied: + + (float) sqrtl ((long double) double_val) -> (float) sqrt (double_val) + */ + if (TYPE_MODE (type) != TYPE_MODE (newtype)) + break; + + int p1 = REAL_MODE_FORMAT (TYPE_MODE (itype))->p; + int p2 = REAL_MODE_FORMAT (TYPE_MODE (newtype))->p; + if (p1 < p2 * 2 + 2) + break; + } + /* Be careful about integer to fp conversions. These may overflow still. */ if (FLOAT_TYPE_P (TREE_TYPE (arg0)) && TYPE_PRECISION (newtype) < TYPE_PRECISION (itype) && (TYPE_MODE (newtype) == TYPE_MODE (double_type_node) || TYPE_MODE (newtype) == TYPE_MODE (float_type_node))) - { + { tree fn = mathfn_built_in (newtype, fcode); if (fn) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2c2cd6..02a436a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-10-24 Cong Hou <congh@google.com> + + * gcc.c-torture/execute/20030125-1.c: Update. + 2013-08-24 Tobias Burnus <burnus@net-b.de> PR fortran/44646 diff --git a/gcc/testsuite/gcc.c-torture/execute/20030125-1.c b/gcc/testsuite/gcc.c-torture/execute/20030125-1.c index 8eb9a42..28cfbd1 100644 --- a/gcc/testsuite/gcc.c-torture/execute/20030125-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/20030125-1.c @@ -44,11 +44,11 @@ __attribute__ ((noinline)) double sin(double a) { - abort (); + return a; } __attribute__ ((noinline)) float sinf(float a) { - return a; + abort (); } |