[PATCH][RFC] Add PAREN_EXPR, make flag_associative_math the default for Fortran

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Thu Jan 3 01:36:00 GMT 2008


Dominique Dhumieres wrote:
> I have found what's wrong for my test with the patch.
> A reduced test case is:
> 
>       real function anint4(x, a, b, c)
>       real, parameter :: f = 2.0**23
>       real x, a, b, c, d, e
>       anint4 = x
>       a = abs(x)
>       if (a < f) then
>          anint4 = (f+a) - f
>          b = anint4
>          c = (anint4 - 0.5) - a
>          if (c > 0.0) then
>             anint4 = anint4 - 1.0 
>          end if
>       end if
>       end function anint4
> 
> If I diff the results of -fdump-tree-optimized with and without
> -ffast-math I get:
> 
> 23c23
> <   D.840 = ((__result_anint4)) - D.832;
> ---
>>   D.840 = ((__result_anint4 - 5.0e-1)) - D.832;
> 
> Do you understand why -ffast-math eats the '-0.5'?

Probably it sees that f + 0.5 == f, and from this derives that
(f + a) - f - 0.5 == (f + a) - f.  Of course this would require an 
invalid reassociation, because the correct expression to evaluate would 
be ((f+a) - f) - 0.5.

Cheers,
- Tobi



More information about the Fortran mailing list