This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Introduce -Ofast
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 21 May 2010 13:49:16 +0200 (CEST)
- Subject: [PATCH] Introduce -Ofast
This adds a new optimization level, -Ofast. It is supposed to glob
options that can alter program behavior or are in conflict with
strict standards compliance only. It adds to options enabled by
-O3 and targets have a hook to enable extra target specific optimizations.
When we add things to -Ofast we should make sure that benchmarks
typically used for the target still execute correctly (we know
that -ffast-math is ok for SPEC CPU for example).
Currently -Ofast only enables -ffast-math.
Bootstrapped on x86_64-unknown-linux-gnu.
Richard.
2010-05-21 Richard Guenther <rguenther@suse.de>
* doc/invoke.texi: Document -Ofast.
* target.h (struct gcc_target): Add handle_ofast.
* target-def.h (TARGET_HANDLE_OFAST): Add.
(TARGET_INITIALIZER): Adjust.
* opts.c (decode_options): Handle -Ofast. Enable
-ffast-math with it.
* common.opt (Ofast): Add.
Index: gcc/target.h
===================================================================
*** gcc/target.h (revision 159654)
--- gcc/target.h (working copy)
*************** struct gcc_target
*** 531,536 ****
--- 531,539 ----
form was. Return true if the switch was valid. */
bool (* handle_option) (size_t code, const char *arg, int value);
+ /* Handle target-specific parts of specifying -Ofast. */
+ void (* handle_ofast) (void);
+
/* Display extra, target specific information in response to a
--target-help switch. */
void (* target_help) (void);
Index: gcc/target-def.h
===================================================================
*** gcc/target-def.h (revision 159654)
--- gcc/target-def.h (working copy)
***************
*** 431,436 ****
--- 431,437 ----
#define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook_void_void
#define TARGET_HANDLE_OPTION hook_bool_size_t_constcharptr_int_true
+ #define TARGET_HANDLE_OFAST hook_void_void
#define TARGET_HELP NULL
/* In except.c */
***************
*** 939,944 ****
--- 940,946 ----
TARGET_DEFAULT_TARGET_FLAGS, \
TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE, \
TARGET_HANDLE_OPTION, \
+ TARGET_HANDLE_OFAST, \
TARGET_HELP, \
TARGET_EH_RETURN_FILTER_MODE, \
TARGET_LIBGCC_CMP_RETURN_MODE, \
Index: gcc/common.opt
===================================================================
*** gcc/common.opt (revision 159654)
--- gcc/common.opt (working copy)
*************** Os
*** 69,74 ****
--- 69,78 ----
Common Optimization
Optimize for space rather than speed
+ Ofast
+ Common Optimization
+ Optimize for speed disregarding exact standards compliance
+
W
Common RejectNegative Var(extra_warnings) Warning
This switch is deprecated; use -Wextra instead
Index: gcc/opts.c
===================================================================
*** gcc/opts.c (revision 159654)
--- gcc/opts.c (working copy)
*************** bool warn_larger_than;
*** 63,69 ****
HOST_WIDE_INT larger_than_size;
/* True to warn about any function whose frame size is larger
! * than N bytes. */
bool warn_frame_larger_than;
HOST_WIDE_INT frame_larger_than_size;
--- 63,69 ----
HOST_WIDE_INT larger_than_size;
/* True to warn about any function whose frame size is larger
! than N bytes. */
bool warn_frame_larger_than;
HOST_WIDE_INT frame_larger_than_size;
*************** decode_options (unsigned int argc, const
*** 804,809 ****
--- 804,810 ----
int opt2;
int opt3;
int opt1_max;
+ int ofast = 0;
if (first_time_p)
{
*************** decode_options (unsigned int argc, const
*** 843,848 ****
--- 844,857 ----
/* Optimizing for size forces optimize to be 2. */
optimize = 2;
+ ofast = 0;
+ }
+ else if (strcmp (p, "fast") == 0)
+ {
+ /* -Ofast only adds flags to -O3. */
+ optimize_size = 0;
+ optimize = 3;
+ ofast = 1;
}
else
{
*************** decode_options (unsigned int argc, const
*** 853,858 ****
--- 862,868 ----
if ((unsigned int) optimize > 255)
optimize = 255;
optimize_size = 0;
+ ofast = 0;
}
}
}
*************** decode_options (unsigned int argc, const
*** 964,969 ****
--- 974,989 ----
/* We want to crossjump as much as possible. */
set_param_value ("min-crossjump-insns", 1);
}
+ else if (ofast)
+ {
+ /* -Ofast adds optimizations to -O3.
+ Which is -ffast-math for now. */
+ set_fast_math_flags (1);
+ /* Allow targets to enable extra options with -Ofast
+ before general options processing so disabling them
+ again afterwards works. */
+ targetm.handle_ofast ();
+ }
else
set_param_value ("min-crossjump-insns", initial_min_crossjump_insns);
Index: gcc/doc/invoke.texi
===================================================================
*** gcc/doc/invoke.texi (revision 159654)
--- gcc/doc/invoke.texi (working copy)
*************** Objective-C and Objective-C++ Dialects}.
*** 393,399 ****
-fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol
-fwhole-program -fwhopr[=@var{n}] -fwpa -fuse-linker-plugin @gol
--param @var{name}=@var{value}
! -O -O0 -O1 -O2 -O3 -Os}
@item Preprocessor Options
@xref{Preprocessor Options,,Options Controlling the Preprocessor}.
--- 393,399 ----
-fvariable-expansion-in-unroller -fvect-cost-model -fvpt -fweb @gol
-fwhole-program -fwhopr[=@var{n}] -fwpa -fuse-linker-plugin @gol
--param @var{name}=@var{value}
! -O -O0 -O1 -O2 -O3 -Os -Ofast}
@item Preprocessor Options
@xref{Preprocessor Options,,Options Controlling the Preprocessor}.
*************** optimizations designed to reduce code si
*** 5888,5893 ****
--- 5888,5900 ----
-falign-labels -freorder-blocks -freorder-blocks-and-partition @gol
-fprefetch-loop-arrays -ftree-vect-loop-version}
+ @item -Ofast
+ @opindex Ofast
+ Disregard strict standards compliance. @option{-Ofast} enables all
+ @option{-O3} optimizations. It also enables optimizations that are not
+ valid for all standard compliant programs.
+ It turns on @option{-ffast-math}.
+
If you use multiple @option{-O} options, with or without level numbers,
the last such option is the one that is effective.
@end table