This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix -Ofast interaction with optimize attributes
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 17 Feb 2011 22:52:42 +0000 (UTC)
- Subject: Fix -Ofast interaction with optimize attributes
Ian recently fixed an issue where -O<level> options (for levels other
than "fast") implicitly setting -fno-fast-math overrode front-end
settings of fast-math options.
Another such issue relates to optimize attributes, which act by
processing an optimization level (the previous one if none was set in
the options in that attribute) before processing other options in that
attribute. Since there is no global setting for -Ofast, an optimize
attribute effectively turns -Ofast from the command line into -O3.
(This is related to PR 38716, but the general problem in that PR is
not a regression and may be comparatively complicated to fix, while
the extension to fast-math options is a regression and is
straightforward to fix.)
This patch arranges for optimize attributes to handle -Ofast
consistently with other options by adding an associated setting in the
gcc_options structure. Bootstrapped with no regressions on
x86_64-unknown-linux-gnu and committed.
2011-02-17 Joseph Myers <joseph@codesourcery.com>
* common.opt (optimize_fast): New Variable.
* opts.c (default_options_optimization): Use opts->x_optimize_fast
instead of local variable ofast.
Index: gcc/opts.c
===================================================================
--- gcc/opts.c (revision 170247)
+++ gcc/opts.c (working copy)
@@ -524,7 +524,6 @@ default_options_optimization (struct gcc
{
unsigned int i;
int opt2;
- int ofast = 0;
/* Scan to see what optimization level has been specified. That will
determine the default value of many flags. */
@@ -538,7 +537,7 @@ default_options_optimization (struct gcc
{
opts->x_optimize = 1;
opts->x_optimize_size = 0;
- ofast = 0;
+ opts->x_optimize_fast = 0;
}
else
{
@@ -553,7 +552,7 @@ default_options_optimization (struct gcc
if ((unsigned int) opts->x_optimize > 255)
opts->x_optimize = 255;
opts->x_optimize_size = 0;
- ofast = 0;
+ opts->x_optimize_fast = 0;
}
}
break;
@@ -563,14 +562,14 @@ default_options_optimization (struct gcc
/* Optimizing for size forces optimize to be 2. */
opts->x_optimize = 2;
- ofast = 0;
+ opts->x_optimize_fast = 0;
break;
case OPT_Ofast:
/* -Ofast only adds flags to -O3. */
opts->x_optimize_size = 0;
opts->x_optimize = 3;
- ofast = 1;
+ opts->x_optimize_fast = 1;
break;
default:
@@ -581,7 +580,7 @@ default_options_optimization (struct gcc
maybe_default_options (opts, opts_set, default_options_table,
opts->x_optimize, opts->x_optimize_size,
- ofast, lang_mask, handlers, loc, dc);
+ opts->x_optimize_fast, lang_mask, handlers, loc, dc);
/* -O2 param settings. */
opt2 = (opts->x_optimize >= 2);
@@ -611,7 +610,7 @@ default_options_optimization (struct gcc
maybe_default_options (opts, opts_set,
targetm.target_option.optimization_table,
opts->x_optimize, opts->x_optimize_size,
- ofast, lang_mask, handlers, loc, dc);
+ opts->x_optimize_fast, lang_mask, handlers, loc, dc);
}
/* After all options at LOC have been read into OPTS and OPTS_SET,
Index: gcc/common.opt
===================================================================
--- gcc/common.opt (revision 170247)
+++ gcc/common.opt (working copy)
@@ -32,6 +32,11 @@ int optimize
Variable
int optimize_size
+; Not used directly to control optimizations, only to save -Ofast
+; setting for "optimize" attributes.
+Variable
+int optimize_fast
+
; 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 multiply and divide.
--
Joseph S. Myers
joseph@codesourcery.com