diff mbox series

Change default optimization level to -Og

Message ID DB6PR0801MB2053E6F13ED5CA0FA6D0D9F483450@DB6PR0801MB2053.eurprd08.prod.outlook.com
State New
Headers show
Series Change default optimization level to -Og | expand

Commit Message

Wilco Dijkstra Oct. 26, 2017, 5:12 p.m. UTC
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?

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.

--

Comments

Eric Gallager Oct. 26, 2017, 6:16 p.m. UTC | #1
On 10/26/17, 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?

There are a number of bugs with -Og that I'd want to see fixed before
making it the default; I'll follow this message up once I find them
all.

>
> 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++)
>
>
Eric Botcazou Oct. 26, 2017, 7:47 p.m. UTC | #2
> GCC's default optimization level is -O0.  Unfortunately unlike other
> compilers, GCC generates extremely inefficient code with -O0.

Agreed (but this can probably be worked on).

> It is almost unusable for low-level debugging or manual inspection of
> generated code. 

Likewise.

> So a -O option is always required for compilation.

For compiler hackers only though.  For normal users, -O0 is still the only 
level where you're guaranteed to be able to do full source debugging.
Jakub Jelinek Oct. 26, 2017, 7:50 p.m. UTC | #3
On Thu, Oct 26, 2017 at 05:12:40PM +0000, Wilco Dijkstra 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?
> 
> 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.

This would only severely confuse users.  -Og has lots of unresolved issues
for debugging experience, and changing the default this way is IMHO
extremely undesirable.

	Jakub
Andrew Pinski Oct. 27, 2017, 4:57 a.m. UTC | #4
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++)
>
Wilco Dijkstra Oct. 27, 2017, 1:04 p.m. UTC | #5
Andrew Pinski wrote:

> 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.

Well it may depend which part of the industry you're coming from. GCC 
certainly has a long history doing it one way, however other compilers took
a different approach and have supported optimized debugging for decades.
So I don't understand the use of having a "turn every optimization off" option,
let alone for it to be the default today...

> 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.

Sure, the doc part of the patch will need further revision if we agree to
change the default.

Wilco
Jeff Law Oct. 27, 2017, 3 p.m. UTC | #6
On 10/26/2017 01:50 PM, Jakub Jelinek wrote:
> On Thu, Oct 26, 2017 at 05:12:40PM +0000, Wilco Dijkstra 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?
>>
>> 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.
> 
> This would only severely confuse users.  -Og has lots of unresolved issues
> for debugging experience, and changing the default this way is IMHO
> extremely undesirable.
And changing a default that has been in place for 30 years just seems
unwise at this point.

jeff
Eric Gallager Oct. 30, 2017, 7:20 p.m. UTC | #7
On Thu, Oct 26, 2017 at 2:16 PM, Eric Gallager <egall@gwmail.gwu.edu> wrote:
> On 10/26/17, 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?
>
> There are a number of bugs with -Og that I'd want to see fixed before
> making it the default; I'll follow this message up once I find them
> all.

update: I've filed bug 82738 to track them all:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82738
https://gcc.gnu.org/ml/gcc-bugs/2017-10/msg03058.html

>
>>
>> 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++)
>>
>>
diff mbox series

Patch

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++)