This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Stop strip_float_extensions removing binary/decimal conversions


On Mon, Oct 27, 2008 at 11:30 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> In the course of looking at various optimizations relating to
> floating-point conversions I noticed that strip_float_extensions would
> remove not only genuine extensions (conversions preserving all values)
> but also conversions between binary and decimal floating-point types,
> and that in turn this could cause some optimizations using this
> function to perform bad transformations, as illustrated by the test
> case added by this patch.
>
> Even with -funsafe-math-optimizations I do not think it makes sense
> for the compiler to remove conversions between binary and decimal
> floating-point types - or to introduce such conversions, as the code
> in strip_float_extensions might have done given a decimal constant
> that can be represented in float.  This patch unconditionally stops
> strip_float_extensions from doing so.  Bootstrapped with no
> regressions on i686-pc-linux-gnu.  OK to commit?

Ok.

Thanks,
Richard.

> 2008-10-27  Joseph Myers  <joseph@codesourcery.com>
>
>        * convert.c (strip_float_extensions): Do not remove or introduce
>        conversions between binary and decimal floating-point types.
>
> testsuite:
> 2008-10-27  Joseph Myers  <joseph@codesourcery.com>
>
>        * gcc.dg/dfp/convert-bfp-12.c: New test.
>
> Index: convert.c
> ===================================================================
> --- convert.c   (revision 141381)
> +++ convert.c   (working copy)
> @@ -81,7 +81,7 @@
>       it properly and handle it like (type)(narrowest_type)constant.
>       This way we can optimize for instance a=a*2.0 where "a" is float
>       but 2.0 is double constant.  */
> -  if (TREE_CODE (exp) == REAL_CST)
> +  if (TREE_CODE (exp) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
>     {
>       REAL_VALUE_TYPE orig;
>       tree type = NULL;
> @@ -108,6 +108,9 @@
>   if (!FLOAT_TYPE_P (subt))
>     return exp;
>
> +  if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
> +    return exp;
> +
>   if (TYPE_PRECISION (subt) > TYPE_PRECISION (expt))
>     return exp;
>
> Index: testsuite/gcc.dg/dfp/convert-bfp-12.c
> ===================================================================
> --- testsuite/gcc.dg/dfp/convert-bfp-12.c       (revision 0)
> +++ testsuite/gcc.dg/dfp/convert-bfp-12.c       (revision 0)
> @@ -0,0 +1,17 @@
> +/* Test for bug where fold wrongly removed conversions to double and
> +   replaced them by conversions to float.  */
> +/* { dg-options "-std=gnu99" } */
> +
> +extern void abort (void);
> +extern void exit (int);
> +
> +volatile float f = __builtin_inff ();
> +volatile _Decimal32 d32 = 1e40DF;
> +
> +int
> +main (void)
> +{
> +  if ((double) f == (double) d32)
> +    abort ();
> +  exit (0);
> +}
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]