maxval on -inf and nan in Fortran

Tobias Burnus tobias@codesourcery.com
Fri Feb 28 09:58:00 GMT 2020


Hi,

(Do you really need to post to gcc@, fortran@ and gcc-patches@?
Shouldn't be one of the list sufficient – like fortran@?)

On 2/28/20 6:02 AM, Jiufu Guo wrote:

> When I check a PR93709, I find the testcase maxlocval_4.f90  […]
> With -ffast-math -O3, this case `STOP 3` on a few platforms, e.g. ppc64le/x86.
To my knowledge, this test case is never be run with -ffast-math;
for sure, it is not run with that option on my x86-64-gnu-linux system.
Given that it uses NaN and INF, it is also not suitable for -ffast-math
(cf. below) – and probably no one has tested or intended to run it with
-ffast-math.

Thus, it is not that unexpected that it fails with -ffast-math. As it
does what it is supposed to do with -O3 and no -ffast-math.

Hence, I fail to understand the problem.

> The test case does not check NaN explicitly.  So, strictly speaking,
> this code may need more stronger to check NaN, otherwise it may STOP
> during execution, and this STOP is acceptable. Right?

In terms of GCC,  "-ffast-math: Sets the options -fno-math-errno,
-funsafe-math-optimizations, -ffinite-math-only, -fno-rounding-math,
-fno-signaling-nans, -fcx-limited-range and -fexcess-precision=fast"
See "man gcc" or https://gcc.gnu.org/onlinedocs/ → GCC Manual
→ "Option Index" or Invoking → Optimization

And in the test case, the neither "mnan" nor "minf" falls under
"finite-math-only".

Regarding -fast-math etc, see also:
https://gcc.gnu.org/wiki/FloatingPointMath
https://gcc.gnu.org/wiki/x87note
https://gcc.gnu.org/wiki/Math_Optimization_Flags

and, talking about FP math in general,
the Goldberg paper, http://www.validlab.com/goldberg/paper.pdf
and similar but both less famous and written more recently:
a paper by Monniaux, https://hal.archives-ouvertes.fr/hal-00128124

Cheers,

Tobias

PS: Using -ffast-math is fine, if one is careful – but one should
then strongly avoid trickery with NaN, INF etc. BTW: Talking about
optimizations, -Ofast (which was not used by you) also enables
-ffast-math but additionally turns implies "-fno-protect-parens",
which otherwise are protected according to the Fortran standard.

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter



More information about the Gcc-patches mailing list