[PATCH v2] Fix -ffast-math flags handling inconsistencies

Jeff Law law@redhat.com
Sat Nov 21 04:33:48 GMT 2020

On 2/11/20 11:43 AM, Ulrich Weigand wrote:
> Hello,
> this second version of the patch incorporates all changes discussed
> in the original mail thread starting here:
> https://gcc.gnu.org/ml/gcc-patches/2020-01/msg02097.html
> The patch now implements the following set of changes:
> 1. If a component flag of -ffast-math (or -funsafe-math-optimizations)
>    is explicitly set (or reset) on the command line, this should override
>    any implicit change due to -f(no-)fast-math, no matter in which order
>    the flags come on the command line.  This change affects all flags.
> 2. Any component flag modified from its default by -ffast-math should
>    be reset to the default by -fno-fast-math.  This was previously
>    not done for the following flags:
>       -fcx-limited-range
>       -fexcess-precision=
> 3. Once -ffinite-math-only is true, the -f(no-)signaling-nans flag has
>    no meaning (if we have no NaNs at all, it does not matter whether
>    there is a difference between quiet and signaling NaNs).  Therefore,
>    it does not make sense for -ffast-math to imply -fno-signaling-nans.
>    This is also a documentation change.
> 4. -ffast-math is documented to imply -fno-rounding-math, however the
>    latter setting is the default anyway; therefore it does not make
>    sense to try to modify it from its default setting.
> 5. The __FAST_MATH__ preprocessor macro should be defined if and only
>    if all the component flags of -ffast-math are set to the value that
>    is documented as the effect of -ffast-math.  The following flags
>    were currently *not* so tested:
>      -fcx-limited-range
>      -fassociative-math
>      -freciprocal-math
>      -frounding-math
>    (Note that we should still *test* for -fno-rounding-math here even
>    though it is not set as per 4.  -ffast-math -frounding-math should
>    not set the __FAST_MATH__ macro.)
>    This is also a documentation change.
> Tested on s390x-ibm-linux.
> OK for mainline?
> Bye,
> Ulrich
> gcc/ChangeLog:
> 	* doc/invoke.texi (-ffast-math): Remove mention of -fno-signaling-nans.
> 	Clarify conditions when __FAST_MATH__ preprocessor macro is defined.
> 	* opts.c (common_handle_option): Pass OPTS_SET to set_fast_math_flags
> 	and set_unsafe_math_optimizations_flags.
> 	(set_fast_math_flags): Add OPTS_SET argument, and use it to avoid
> 	setting flags already explicitly set on the command line.  In the !set
> 	case, also reset x_flag_cx_limited_range and x_flag_excess_precision.
> 	Never reset x_flag_signaling_nans or x_flag_rounding_math.
> 	(set_unsafe_math_optimizations_flags): Add OPTS_SET argument, and use
> 	it to avoid setting flags already explicitly set on the command line.
> 	(fast_math_flags_set_p): Also test x_flag_cx_limited_range,
> 	x_flag_associative_math, x_flag_reciprocal_math, and
> 	x_flag_rounding_math.
It appears this was dropped on the floor.  It looks reasonable to me. 
Please retest and commit.  Thanks!


More information about the Gcc-patches mailing list