This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed to trunk], was: Re: [RFD] -ffinite-math-only.
Toon Moene wrote:
> Richard Henderson wrote:
> > On Mon, Jul 29, 2002 at 01:07:20PM +0200, Toon Moene wrote:
> > > Often, one knows that a program won't generate (or consume) NaNs and
> > > Infinities; it would be nice if the compiler could be told about that fact.
> > Even if this weren't the case, it's somewhat nice to see it split
> > out from the flag_unsafe_math_optimizations blob.
> > Would you be interested in combing the remaining uses of
> > flag_unsafe_math_optimizations for things that ought to be
> > flag_finite_math_only or one of the HONOR_FOO macros?
> Sure, despite all the hype that we can now make the substitution x*0 -> 0
> it still doesn't happen.
> > I see two right away at combine.c:4776.
> Fixed into (!FLOAT_MODE_P (mode) || !HONOR_NANS (mode))
> which will be installed after another make bootstrap / make -k check on
> i686-pc-linux-gnu.
I committed the following [attached] after make bootstrap, make -k check
and make install on i686-pc-linux-gnu.
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
2002-07-29 Toon Moene <toon@moene.indiv.nluug.nl>
* flags.h: Declare flag_finite_math_only.
Use it in definition of HONOR_NANS and
HONOR_INFINITIES.
* c-common.c (cb_register_builtins): Emit
__FINITE_MATH_ONLY__ when flag_finite_math_only
is set.
* combine.c (simplify_if_then_else): If
flag_finite_math_only is set, a == b has a
definite value.
* toplev.c: Initialize flag_finite_math_only.
(set_flags_fast_math): Set it on -ffast-math.
(flag_fast_math_set_p): Test it.
doc:
* invoke.texi: Document -ffinite-math-only.
f:
* com.c (ffe_init_options): Set
flag_finite_math_only.
* invoke.texi: Document -fno-finite-math-only.
*** flags.h.orig Sun Jul 28 16:20:30 2002
--- flags.h Sun Jul 28 16:28:24 2002
*************** extern int flag_errno_math;
*** 360,363 ****
--- 360,367 ----
extern int flag_unsafe_math_optimizations;
+ /* Nonzero means that no NaNs or +-Infs are expected. */
+
+ extern int flag_finite_math_only;
+
/* Zero means that floating-point math operations cannot generate a
(user-visible) trap. This is the case, for example, in nonstop
*************** extern int flag_signaling_nans;
*** 673,677 ****
done anyway using the -funsafe-math-optimizations switch. */
#define HONOR_NANS(MODE) \
! (MODE_HAS_NANS (MODE) && !flag_unsafe_math_optimizations)
/* Like HONOR_NANs, but true if we honor signaling NaNs (or sNaNs). */
--- 677,681 ----
done anyway using the -funsafe-math-optimizations switch. */
#define HONOR_NANS(MODE) \
! (MODE_HAS_NANS (MODE) && !flag_finite_math_only)
/* Like HONOR_NANs, but true if we honor signaling NaNs (or sNaNs). */
*************** extern int flag_signaling_nans;
*** 681,685 ****
the treatment of infinite values is important. */
#define HONOR_INFINITIES(MODE) \
! (MODE_HAS_INFINITIES (MODE) && !flag_unsafe_math_optimizations)
/* Like HONOR_NANS, but true if the given mode distinguishes between
--- 685,689 ----
the treatment of infinite values is important. */
#define HONOR_INFINITIES(MODE) \
! (MODE_HAS_INFINITIES (MODE) && !flag_finite_math_only)
/* Like HONOR_NANS, but true if the given mode distinguishes between
*** c-common.c.orig Sun Jul 28 16:20:30 2002
--- c-common.c Tue Jul 30 16:16:44 2002
*************** cb_register_builtins (pfile)
*** 4386,4389 ****
--- 4386,4391 ----
if (flag_signaling_nans)
cpp_define (pfile, "__SUPPORT_SNAN__");
+ if (flag_finite_math_only)
+ cpp_define (pfile, "__FINITE_MATH_ONLY__");
if (flag_iso)
*** combine.c.orig Fri Jul 12 20:42:45 2002
--- combine.c Tue Jul 30 16:25:30 2002
*************** simplify_if_then_else (x)
*** 4776,4785 ****
/* Convert a == b ? b : a to "a". */
if (true_code == EQ && ! side_effects_p (cond)
! && (! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
&& rtx_equal_p (XEXP (cond, 0), false_rtx)
&& rtx_equal_p (XEXP (cond, 1), true_rtx))
return false_rtx;
else if (true_code == NE && ! side_effects_p (cond)
! && (! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
&& rtx_equal_p (XEXP (cond, 0), true_rtx)
&& rtx_equal_p (XEXP (cond, 1), false_rtx))
--- 4776,4785 ----
/* Convert a == b ? b : a to "a". */
if (true_code == EQ && ! side_effects_p (cond)
! && (!FLOAT_MODE_P (mode) || !HONOR_NANS (mode))
&& rtx_equal_p (XEXP (cond, 0), false_rtx)
&& rtx_equal_p (XEXP (cond, 1), true_rtx))
return false_rtx;
else if (true_code == NE && ! side_effects_p (cond)
! && (!FLOAT_MODE_P (mode) || !HONOR_NANS (mode))
&& rtx_equal_p (XEXP (cond, 0), true_rtx)
&& rtx_equal_p (XEXP (cond, 1), false_rtx))
*** toplev.c.orig Sun Jul 28 16:20:31 2002
--- toplev.c Sun Jul 28 16:23:27 2002
*************** int flag_errno_math = 1;
*** 576,579 ****
--- 576,583 ----
int flag_unsafe_math_optimizations = 0;
+ /* Nonzero means that no NaNs or +-Infs are expected. */
+
+ int flag_finite_math_only = 0;
+
/* Zero means that floating-point math operations cannot generate a
(user-visible) trap. This is the case, for example, in nonstop
*************** static const lang_independent_options f_
*** 1171,1174 ****
--- 1175,1180 ----
{ "peephole2", &flag_peephole2, 1,
N_("Enables an rtl peephole pass run before sched2") },
+ {"finite-math-only", &flag_finite_math_only, 1,
+ N_("Assume no NaNs or +-Infs are generated") },
{ "guess-branch-probability", &flag_guess_branch_prob, 1,
N_("Enables guessing of branch probabilities") },
*************** set_fast_math_flags (set)
*** 1576,1579 ****
--- 1582,1586 ----
flag_trapping_math = !set;
flag_unsafe_math_optimizations = set;
+ flag_finite_math_only = set;
flag_errno_math = !set;
if (set)
*************** fast_math_flags_set_p ()
*** 1587,1590 ****
--- 1594,1598 ----
return (!flag_trapping_math
&& flag_unsafe_math_optimizations
+ && flag_finite_math_only
&& !flag_errno_math);
}
*** doc/invoke.texi.orig Sun Jul 28 16:20:34 2002
--- doc/invoke.texi Sun Jul 28 16:25:27 2002
*************** in the following sections.
*** 274,278 ****
-fno-function-cse -fno-guess-branch-probability @gol
-fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol
! -funsafe-math-optimizations -fno-trapping-math @gol
-fno-zero-initialized-in-bss @gol
-fomit-frame-pointer -foptimize-register-move @gol
--- 274,278 ----
-fno-function-cse -fno-guess-branch-probability @gol
-fno-inline -fno-math-errno -fno-peephole -fno-peephole2 @gol
! -funsafe-math-optimizations -ffinite-math-only -fno-trapping-math @gol
-fno-zero-initialized-in-bss @gol
-fomit-frame-pointer -foptimize-register-move @gol
*************** performed when this option is not used.
*** 3409,3413 ****
@opindex ffast-math
Sets @option{-fno-math-errno}, @option{-funsafe-math-optimizations}, @*
! @option{-fno-trapping-math} and @option{-fno-signaling-nans}.
This option causes the preprocessor macro @code{__FAST_MATH__} to be defined.
--- 3409,3414 ----
@opindex ffast-math
Sets @option{-fno-math-errno}, @option{-funsafe-math-optimizations}, @*
! @option{-fno-trapping-math}, @option{-ffinite-math-only} and @*
! @option{-fno-signaling-nans}.
This option causes the preprocessor macro @code{__FAST_MATH__} to be defined.
*************** math functions.
*** 3446,3449 ****
--- 3447,3461 ----
The default is @option{-fno-unsafe-math-optimizations}.
+
+ @item -ffinite-math-only
+ @opindex ffinite-math-only
+ Allow optimizations for floating-point arithmetic that assume
+ that arguments and results are not NaNs or +-Infs.
+
+ This option should never be turned on by any @option{-O} option since
+ it can result in incorrect output for programs which depend on
+ an exact implementation of IEEE or ISO rules/specifications.
+
+ The default is @option{-fno-finite-math-only}.
@item -fno-trapping-math
*** f/com.c.orig Thu Jul 25 14:56:44 2002
--- f/com.c Tue Jul 30 15:03:29 2002
*************** ffe_init_options ()
*** 14177,14180 ****
--- 14177,14181 ----
flag_argument_noalias = 2;
flag_merge_constants = 2;
+ flag_finite_math_only = 1;
flag_errno_math = 0;
flag_complex_divide_method = 1;
*************** read_name_map (dirname)
*** 15313,15320 ****
dirlen = strlen (dirname);
separator_needed = dirlen != 0 && dirname[dirlen - 1] != '/';
! name = (char *) xmalloc (dirlen + strlen (FILE_NAME_MAP_FILE) + 2);
! strcpy (name, dirname);
! name[dirlen] = '/';
! strcpy (name + dirlen + separator_needed, FILE_NAME_MAP_FILE);
f = fopen (name, "r");
free (name);
--- 15314,15321 ----
dirlen = strlen (dirname);
separator_needed = dirlen != 0 && dirname[dirlen - 1] != '/';
! if (separator_needed)
! name = concat (dirname, "/", FILE_NAME_MAP_FILE, NULL);
! else
! name = concat (dirname, FILE_NAME_MAP_FILE, NULL);
f = fopen (name, "r");
free (name);
*************** read_name_map (dirname)
*** 15346,15353 ****
else
{
! ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
! strcpy (ptr->map_to, dirname);
! ptr->map_to[dirlen] = '/';
! strcpy (ptr->map_to + dirlen + separator_needed, to);
free (to);
}
--- 15347,15354 ----
else
{
! if (separator_needed)
! ptr->map_to = concat (dirname, "/", to, NULL);
! else
! ptr->map_to = concat (dirname, to, NULL);
free (to);
}
*** f/invoke.texi.orig Thu Jul 25 14:56:45 2002
--- f/invoke.texi Sun Jul 28 16:23:53 2002
*************** by type. Explanations are in the follow
*** 183,187 ****
-ffloat-store -fforce-mem -fforce-addr -fno-inline @gol
-ffast-math -fstrength-reduce -frerun-cse-after-loop @gol
! -funsafe-math-optimizations -fno-trapping-math @gol
-fexpensive-optimizations -fdelayed-branch @gol
-fschedule-insns -fschedule-insn2 -fcaller-saves @gol
--- 183,187 ----
-ffloat-store -fforce-mem -fforce-addr -fno-inline @gol
-ffast-math -fstrength-reduce -frerun-cse-after-loop @gol
! -funsafe-math-optimizations -fno-finite-math-only -fno-trapping-math @gol
-fexpensive-optimizations -fdelayed-branch @gol
-fschedule-insns -fschedule-insn2 -fcaller-saves @gol
*************** Sets @option{-funsafe-math-optimizations
*** 1551,1554 ****
--- 1551,1564 ----
Allow optimizations that may be give incorrect results
for certain IEEE inputs.
+
+ @cindex -fno-finite-math-only option
+ @cindex options, -fno-finite-math-only
+ @item -fno-finite-math-only
+ Fortran specifies all arithmetic that can result in a NaN or an
+ infinity as "giving undefined results", therefore the compiler
+ by default operates in a way that assumes no NaNs or +-Inf can
+ be generated. If you want to use a NaN or an Inf produced by
+ means other than Fortran, use this option to compile your
+ Fortran program.
@cindex -fno-trapping-math option