toplev.c (flag_rounding_math): New global variable.
authorRoger Sayle <roger@eyesopen.com>
Wed, 3 Sep 2003 20:57:31 +0000 (20:57 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Wed, 3 Sep 2003 20:57:31 +0000 (20:57 +0000)
* toplev.c (flag_rounding_math): New global variable.
(f_options): Add to the list of language independent options.
* flags.h (flag_rounding_math): Prototype here.
(HONOR_SIGN_DEPENDENT_ROUNDING): Use flag_rounding_math instead.
* common.opt (frounding-math): New common command line option.
* opts.c (common_handle_option): Handle OPT_frounding_math.
(set_fast_math_flags): -ffast-math clears flag_rounding_math.

* doc/invoke.texi: Document this new command line option.

From-SVN: r71032

gcc/ChangeLog
gcc/common.opt
gcc/doc/invoke.texi
gcc/flags.h
gcc/opts.c
gcc/toplev.c

index 10e6681aa26b8401e80131abd8ec3162910339eb..91ad0d7299d7db22c733f06ef25ffe7562ecc1e0 100644 (file)
@@ -1,3 +1,15 @@
+2003-09-03  Roger Sayle  <roger@eyesopen.com>
+
+       * toplev.c (flag_rounding_math): New global variable.
+       (f_options): Add to the list of language independent options.
+       * flags.h (flag_rounding_math): Prototype here.
+       (HONOR_SIGN_DEPENDENT_ROUNDING): Use flag_rounding_math instead.
+       * common.opt (frounding-math): New common command line option.
+       * opts.c (common_handle_option): Handle OPT_frounding_math.
+       (set_fast_math_flags): -ffast-math clears flag_rounding_math.
+
+       * doc/invoke.texi: Document this new command line option.
+
 2003-09-03  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
 
        * config/sol2.h (NO_IMPLICIT_EXTERN_C): Update comment.
index 546e738850579af84a9d6936b2928a8b5fb8f5f3..68c37b0c69612efdc071982ef351576b7188cbdc 100644 (file)
@@ -552,6 +552,10 @@ frerun-loop-opt
 Common
 Run the loop optimizer twice
 
+frounding-math
+Common
+Disable optimizations that assume default FP rounding behavior
+
 fsched-interblock
 Common
 Enable scheduling across basic blocks
index fb4cf782388da336137a8aea24b5b80f36cb48f2..359e64fa6080ef1e33511a19691f89b58dfe8f8c 100644 (file)
@@ -280,7 +280,7 @@ in the following sections.
 -freduce-all-givs  -fregmove  -frename-registers @gol
 -freorder-blocks  -freorder-functions @gol
 -frerun-cse-after-loop  -frerun-loop-opt @gol
--fschedule-insns  -fschedule-insns2 @gol
+-frounding-math -fschedule-insns  -fschedule-insns2 @gol
 -fno-sched-interblock  -fno-sched-spec  -fsched-spec-load @gol
 -fsched-spec-load-dangerous  -fsched2-use-superblocks @gol
 -fsched2-use-traces  -fsignaling-nans @gol
@@ -4260,8 +4260,8 @@ them to store all pertinent intermediate computations into variables.
 @item -ffast-math
 @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}.
+@option{-fno-trapping-math}, @option{-ffinite-math-only},
+@option{-fno-rounding-math} and @option{-fno-signaling-nans}.
 
 This option causes the preprocessor macro @code{__FAST_MATH__} to be defined.
 
@@ -4325,6 +4325,26 @@ math functions.
 
 The default is @option{-ftrapping-math}.
 
+@item -frounding-math
+@opindex frounding-math
+Disable transformations and optimizations that assume default floating
+point rounding behavior.  This is round-to-zero for all floating point
+to integer conversions, and round-to-nearest for all other arithmetic
+truncations.  This option should be specified for programs that change
+the FP rounding mode dynamically, or that may be executed with a
+non-default rounding mode.  This option disables constant folding of
+floating point expressions at compile-time (which may be affected by
+rounding mode) and arithmetic transformations that are unsafe in the
+presence of sign-dependent rounding modes.
+
+The default is @option{-fno-rounding-math}.
+
+This option is experimental and does not currently guarantee to
+disable all GCC optimizations that are affected by rounding mode.
+Future versions of gcc may provide finer control of this setting
+using C99's @code{FENV_ACCESS} pragma.  This command line option
+will be used to specify the default state for @code{FENV_ACCESS}.
+
 @item -fsignaling-nans
 @opindex fsignaling-nans
 Compile code assuming that IEEE signaling NaNs may generate user-visible
index 6195fee365d9e5b7b90c738237e288df27b9b5ef..823aaefb32d08d53d5d14d13c9999668da488399 100644 (file)
@@ -363,6 +363,11 @@ extern int flag_finite_math_only;
 
 extern int flag_trapping_math;
 
+/* Nonzero means disable transformations that assume default floating
+   point rounding behavior.  */
+
+extern int flag_rounding_math;
+
 /* 0 means straightforward implementation of complex divide acceptable.
    1 means wide ranges of inputs must work for complex divide.
    2 means C99-like requirements for complex divide (not yet implemented).  */
@@ -716,6 +721,6 @@ extern const char *flag_random_seed;
 /* Like HONOR_NANS, but true if given mode supports sign-dependent rounding,
    and the rounding mode is important.  */
 #define HONOR_SIGN_DEPENDENT_ROUNDING(MODE) \
-  (MODE_HAS_SIGN_DEPENDENT_ROUNDING (MODE) && !flag_unsafe_math_optimizations)
+  (MODE_HAS_SIGN_DEPENDENT_ROUNDING (MODE) && flag_rounding_math)
 
 #endif /* ! GCC_FLAGS_H */
index 24741da5588cf7da43961339a26afe95516a6545..fe8d28f560470b27e602474438c3231ea623329a 100644 (file)
@@ -1220,8 +1220,12 @@ common_handle_option (size_t scode, const char *arg,
       flag_rerun_loop_opt = value;
       break;
 
+    case OPT_frounding_math:
+      flag_rounding_math = value;
+      break;
+
     case OPT_fsched_interblock:
-      flag_schedule_interblock= value;
+      flag_schedule_interblock = value;
       break;
 
     case OPT_fsched_spec:
@@ -1547,7 +1551,10 @@ set_fast_math_flags (int set)
   flag_finite_math_only = set;
   flag_errno_math = !set;
   if (set)
-    flag_signaling_nans = 0;
+    {
+      flag_signaling_nans = 0;
+      flag_rounding_math = 0;
+    }
 }
 
 /* Return true iff flags are set as if -ffast-math.  */
index 3e639c6a151c8a6033ef1efaecd0ff7e67d8b6e7..b98538568e3037728ecf97f1711806c070fe05cc 100644 (file)
@@ -633,6 +633,11 @@ int flag_finite_math_only = 0;
 
 int flag_trapping_math = 1;
 
+/* Nonzero means disable transformations that assume default floating
+   point rounding behavior.  */
+
+int flag_rounding_math = 0;
+
 /* Nonzero means disable transformations observable by signaling NaNs.
    This option implies that any operation on an IEEE signaling NaN can
    generate a (user-visible) trap.  */
@@ -1113,6 +1118,7 @@ static const lang_independent_options f_options[] =
   { "guess-branch-probability", &flag_guess_branch_prob, 1 },
   {"math-errno", &flag_errno_math, 1 },
   {"trapping-math", &flag_trapping_math, 1 },
+  {"rounding-math", &flag_rounding_math, 1 },
   {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
   {"signaling-nans", &flag_signaling_nans, 1 },
   {"bounds-check", &flag_bounds_check, 1 },