public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Change default optimization level to -Og
@ 2017-10-26 17:13 Wilco Dijkstra
  2017-10-26 18:20 ` Eric Gallager
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Wilco Dijkstra @ 2017-10-26 17:13 UTC (permalink / raw)
  To: GCC Patches; +Cc: nd

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.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-26 17:13 [PATCH] Change default optimization level to -Og Wilco Dijkstra
@ 2017-10-26 18:20 ` Eric Gallager
  2017-10-30 19:23   ` Eric Gallager
  2017-10-26 19:50 ` Eric Botcazou
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Eric Gallager @ 2017-10-26 18:20 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: GCC Patches, nd

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-26 17:13 [PATCH] Change default optimization level to -Og Wilco Dijkstra
  2017-10-26 18:20 ` Eric Gallager
@ 2017-10-26 19:50 ` Eric Botcazou
  2017-10-26 19:57 ` Jakub Jelinek
  2017-10-27  6:50 ` Andrew Pinski
  3 siblings, 0 replies; 8+ messages in thread
From: Eric Botcazou @ 2017-10-26 19:50 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: gcc-patches, nd

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

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-26 17:13 [PATCH] Change default optimization level to -Og Wilco Dijkstra
  2017-10-26 18:20 ` Eric Gallager
  2017-10-26 19:50 ` Eric Botcazou
@ 2017-10-26 19:57 ` Jakub Jelinek
  2017-10-27 15:13   ` Jeff Law
  2017-10-27  6:50 ` Andrew Pinski
  3 siblings, 1 reply; 8+ messages in thread
From: Jakub Jelinek @ 2017-10-26 19:57 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: GCC Patches, nd

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-26 17:13 [PATCH] Change default optimization level to -Og Wilco Dijkstra
                   ` (2 preceding siblings ...)
  2017-10-26 19:57 ` Jakub Jelinek
@ 2017-10-27  6:50 ` Andrew Pinski
  2017-10-27 13:04   ` Wilco Dijkstra
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Pinski @ 2017-10-27  6:50 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: GCC Patches, nd

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-27  6:50 ` Andrew Pinski
@ 2017-10-27 13:04   ` Wilco Dijkstra
  0 siblings, 0 replies; 8+ messages in thread
From: Wilco Dijkstra @ 2017-10-27 13:04 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: GCC Patches, nd

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-26 19:57 ` Jakub Jelinek
@ 2017-10-27 15:13   ` Jeff Law
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Law @ 2017-10-27 15:13 UTC (permalink / raw)
  To: Jakub Jelinek, Wilco Dijkstra; +Cc: GCC Patches, nd

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Change default optimization level to -Og
  2017-10-26 18:20 ` Eric Gallager
@ 2017-10-30 19:23   ` Eric Gallager
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Gallager @ 2017-10-30 19:23 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: GCC Patches, nd

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-10-30 19:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-26 17:13 [PATCH] Change default optimization level to -Og Wilco Dijkstra
2017-10-26 18:20 ` Eric Gallager
2017-10-30 19:23   ` Eric Gallager
2017-10-26 19:50 ` Eric Botcazou
2017-10-26 19:57 ` Jakub Jelinek
2017-10-27 15:13   ` Jeff Law
2017-10-27  6:50 ` Andrew Pinski
2017-10-27 13:04   ` Wilco Dijkstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).