This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Change default optimization level to -Og


On Thu, Oct 26, 2017 at 10:12 AM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> GCC's default optimization level is -O0.  Unfortunately unlike other compilers,
> GCC generates extremely inefficient code with -O0.  It is almost unusable for
> low-level debugging or manual inspection of generated code.  So a -O option is
> always required for compilation.  -Og not only allows for fast compilation, but
> also produces code that is efficient, readable as well as debuggable.
> Therefore -Og makes for a much better default setting.
>
> Any comments?


I think this goes against what most folks are used to.  I know you are
saying most folks are used to a compiler defaulting to optimizations
on but I don't think that is true.  In fact GCC has been this way
since day one.

Plus you also missed changing the following part of the documentation:
If you are not using some other optimization option, consider using
-Og (see Optimize Options) with -g. With no -O option at all, some
compiler passes that collect information useful for debugging do not
run at all, so that -Og may result in a better debugging experience.

Thanks,
Andrew Pinski

>
> 2017-10-26  Wilco Dijkstra  <wdijkstr@arm.com>
>
>         * opts.c (default_options_optimization): Set default to -Og.
>
> doc/
>         * invoke.texi (-O0) Remove default mention.
>         (-Og): Add mention of default setting.
>
> --
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 3328a3b5fafa6a98007eff52d2a26af520de9128..74c33ea35b9f320b419a3417e6007d2391536f1b 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -7343,7 +7343,7 @@ by @option{-O2} and also turns on the following optimization flags:
>  @item -O0
>  @opindex O0
>  Reduce compilation time and make debugging produce the expected
> -results.  This is the default.
> +results.
>
>  @item -Os
>  @opindex Os
> @@ -7371,7 +7371,7 @@ Optimize debugging experience.  @option{-Og} enables optimizations
>  that do not interfere with debugging. It should be the optimization
>  level of choice for the standard edit-compile-debug cycle, offering
>  a reasonable level of optimization while maintaining fast compilation
> -and a good debugging experience.
> +and a good debugging experience.  This is the default.
>  @end table
>
>  If you use multiple @option{-O} options, with or without level numbers,
> diff --git a/gcc/opts.c b/gcc/opts.c
> index dfad955e220870a3250198640f3790c804b191e0..74511215309f11445685db4894be2ab6881695d3 100644
> --- a/gcc/opts.c
> +++ b/gcc/opts.c
> @@ -565,6 +565,12 @@ default_options_optimization (struct gcc_options *opts,
>    int opt2;
>    bool openacc_mode = false;
>
> +  /* Set the default optimization to -Og.  */
> +  opts->x_optimize_size = 0;
> +  opts->x_optimize = 1;
> +  opts->x_optimize_fast = 0;
> +  opts->x_optimize_debug = 1;
> +
>    /* Scan to see what optimization level has been specified.  That will
>       determine the default value of many flags.  */
>    for (i = 1; i < decoded_options_count; i++)
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]