* Re: [EXTERNAL] Re: question about knowing when optimization options are used
2020-03-16 23:34 ` Segher Boessenkool
@ 2020-03-16 23:55 ` Shrader, David Lee
2020-03-17 0:36 ` Segher Boessenkool
2020-03-17 1:35 ` Jeffrey Walton
2020-03-17 12:22 ` Richard Sandiford
` (2 subsequent siblings)
3 siblings, 2 replies; 13+ messages in thread
From: Shrader, David Lee @ 2020-03-16 23:55 UTC (permalink / raw)
To: Segher Boessenkool; +Cc: gcc-help
Hello,
Thank you for the reply. So, what you're saying is that the output of `gcc -Q --help=optimizers` doesn't necessarily reflect what optimization gcc is going to do when -O0 is being used, correct? This is because no (or very little) optimization is actually allowed to be done when -O0 is use.
Thank you again for the help!
David
________________________________
From: Segher Boessenkool <segher@kernel.crashing.org>
Sent: Monday, March 16, 2020 5:34 PM
To: Shrader, David Lee
Cc: gcc-help@gcc.gnu.org
Subject: [EXTERNAL] Re: question about knowing when optimization options are used
On Mon, Mar 16, 2020 at 11:14:25PM +0000, Shrader, David Lee via Gcc-help wrote:
> Most optimizations are only enabled if an -O level is set on the command line. Otherwise they are disabled, even if individual optimization flags are specified.
Yes.
> The man page says to use `-Q --help=optimizers` to find out what is turned on for the different -O levels as configure-time options can make things different from the defaults shown later in that man page. However, I have found that, even when using -O0, I can turn on optimization options, at least according to the help output:
You can enable the *flags*, sure, but with -O0 those flags do not do
anything. Exactly as the text above says? The "even if" part.
Segher
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [EXTERNAL] Re: question about knowing when optimization options are used
2020-03-16 23:55 ` [EXTERNAL] " Shrader, David Lee
@ 2020-03-17 0:36 ` Segher Boessenkool
2020-03-17 1:39 ` Shrader, David Lee
2020-03-17 1:35 ` Jeffrey Walton
1 sibling, 1 reply; 13+ messages in thread
From: Segher Boessenkool @ 2020-03-17 0:36 UTC (permalink / raw)
To: Shrader, David Lee; +Cc: gcc-help
Hi!
On Mon, Mar 16, 2020 at 11:55:01PM +0000, Shrader, David Lee wrote:
> Thank you for the reply. So, what you're saying is that the output of `gcc -Q --help=optimizers` doesn't necessarily reflect what optimization gcc is going to do when -O0 is being used, correct? This is because no (or very little) optimization is actually allowed to be done when -O0 is use.
Yes. Some of the documentation isn't clear on this, but in context it
should be clear?
Segher
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [EXTERNAL] Re: question about knowing when optimization options are used
2020-03-17 0:36 ` Segher Boessenkool
@ 2020-03-17 1:39 ` Shrader, David Lee
0 siblings, 0 replies; 13+ messages in thread
From: Shrader, David Lee @ 2020-03-17 1:39 UTC (permalink / raw)
To: Segher Boessenkool; +Cc: gcc-help
It’s clear to me now. After reading through the optimization section again, I can see more of the meaning; perhaps because I am looking for it. Thank you for taking the time to answer.
David
From: Segher Boessenkool <segher@kernel.crashing.org<mailto:segher@kernel.crashing.org>>
Date: Monday, Mar 16, 2020, 6:36 PM
To: Shrader, David Lee <dshrader@lanl.gov<mailto:dshrader@lanl.gov>>
Cc: gcc-help@gcc.gnu.org <gcc-help@gcc.gnu.org<mailto:gcc-help@gcc.gnu.org>>
Subject: Re: [EXTERNAL] Re: question about knowing when optimization options are used
Hi!
On Mon, Mar 16, 2020 at 11:55:01PM +0000, Shrader, David Lee wrote:
> Thank you for the reply. So, what you're saying is that the output of `gcc -Q --help=optimizers` doesn't necessarily reflect what optimization gcc is going to do when -O0 is being used, correct? This is because no (or very little) optimization is actually allowed to be done when -O0 is use.
Yes. Some of the documentation isn't clear on this, but in context it
should be clear?
Segher
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [EXTERNAL] Re: question about knowing when optimization options are used
2020-03-16 23:55 ` [EXTERNAL] " Shrader, David Lee
2020-03-17 0:36 ` Segher Boessenkool
@ 2020-03-17 1:35 ` Jeffrey Walton
2020-03-17 1:44 ` Shrader, David Lee
1 sibling, 1 reply; 13+ messages in thread
From: Jeffrey Walton @ 2020-03-17 1:35 UTC (permalink / raw)
To: gcc-help
On Mon, Mar 16, 2020 at 7:55 PM Shrader, David Lee via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> Thank you for the reply. So, what you're saying is that the output of `gcc -Q --help=optimizers` doesn't necessarily reflect what optimization gcc is going to do when -O0 is being used, correct? This is because no (or very little) optimization is actually allowed to be done when -O0 is use.
If you are interested in debugging+optimizations, then you might also
take a look at -Og. It is a relatively new option that is intended to
apply some optimizations while preserving the debugging experience. I
think it showed up around GCC 7, but the first mention in the change
log is GCC 8. Also see
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html .
$ gcc -Og -Q --help=optimizers | grep "\-fmove-loop-invariants"
-fmove-loop-invariants [disabled]
$ gcc -O3 -Q --help=optimizers | grep "\-fmove-loop-invariants"
-fmove-loop-invariants [enabled]
Jeff
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [EXTERNAL] Re: question about knowing when optimization options are used
2020-03-17 1:35 ` Jeffrey Walton
@ 2020-03-17 1:44 ` Shrader, David Lee
2020-03-17 2:58 ` Segher Boessenkool
0 siblings, 1 reply; 13+ messages in thread
From: Shrader, David Lee @ 2020-03-17 1:44 UTC (permalink / raw)
To: noloader, gcc-help
Actually, I am interested in looking in to that. I end up fielding a lot of questions about what to do for adequate debugging, and I wasn’t aware of that flag. Thank you for pointing it out to me.
David
From: Jeffrey Walton via Gcc-help <gcc-help@gcc.gnu.org<mailto:gcc-help@gcc.gnu.org>>
Date: Monday, Mar 16, 2020, 7:35 PM
To: gcc-help <gcc-help@gcc.gnu.org<mailto:gcc-help@gcc.gnu.org>>
Subject: Re: [EXTERNAL] Re: question about knowing when optimization options are used
On Mon, Mar 16, 2020 at 7:55 PM Shrader, David Lee via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> Thank you for the reply. So, what you're saying is that the output of `gcc -Q --help=optimizers` doesn't necessarily reflect what optimization gcc is going to do when -O0 is being used, correct? This is because no (or very little) optimization is actually allowed to be done when -O0 is use.
If you are interested in debugging+optimizations, then you might also
take a look at -Og. It is a relatively new option that is intended to
apply some optimizations while preserving the debugging experience. I
think it showed up around GCC 7, but the first mention in the change
log is GCC 8. Also see
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html .
$ gcc -Og -Q --help=optimizers | grep "\-fmove-loop-invariants"
-fmove-loop-invariants [disabled]
$ gcc -O3 -Q --help=optimizers | grep "\-fmove-loop-invariants"
-fmove-loop-invariants [enabled]
Jeff
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [EXTERNAL] Re: question about knowing when optimization options are used
2020-03-17 1:44 ` Shrader, David Lee
@ 2020-03-17 2:58 ` Segher Boessenkool
0 siblings, 0 replies; 13+ messages in thread
From: Segher Boessenkool @ 2020-03-17 2:58 UTC (permalink / raw)
To: Shrader, David Lee; +Cc: noloader, gcc-help
On Tue, Mar 17, 2020 at 01:44:48AM +0000, Shrader, David Lee via Gcc-help wrote:
> Actually, I am interested in looking in to that. I end up fielding a lot of questions about what to do for adequate debugging, and I wasn’t aware of that flag. Thank you for pointing it out to me.
-Og was introduced in GCC 4.8, seven years ago.
Segher
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question about knowing when optimization options are used
2020-03-16 23:34 ` Segher Boessenkool
2020-03-16 23:55 ` [EXTERNAL] " Shrader, David Lee
@ 2020-03-17 12:22 ` Richard Sandiford
2020-03-18 20:15 ` Segher Boessenkool
2020-03-18 17:44 ` mark_at_yahoo
2020-03-19 14:17 ` Jonathan Wakely
3 siblings, 1 reply; 13+ messages in thread
From: Richard Sandiford @ 2020-03-17 12:22 UTC (permalink / raw)
To: Segher Boessenkool; +Cc: Shrader, David Lee, gcc-help
Segher Boessenkool <segher@kernel.crashing.org> writes:
> On Mon, Mar 16, 2020 at 11:14:25PM +0000, Shrader, David Lee via Gcc-help wrote:
>> Most optimizations are only enabled if an -O level is set on the command line. Otherwise they are disabled, even if individual optimization flags are specified.
>
> Yes.
>
>> The man page says to use `-Q --help=optimizers` to find out what is turned on for the different -O levels as configure-time options can make things different from the defaults shown later in that man page. However, I have found that, even when using -O0, I can turn on optimization options, at least according to the help output:
>
> You can enable the *flags*, sure, but with -O0 those flags do not do
> anything. Exactly as the text above says? The "even if" part.
I think David's the right that the wording isn't clear though.
The documentation sets up a contrast between an option being "enabled"
or merely "specified", with "enabled" meaning something like "have an
effect". But the quoted output then undermines that by using "enabled"
for what the documentation calls "specified":
$> gcc -Q --help=optimizers -fmove-loop-invariants | grep "\-fmove-loop-invariants"
-fmove-loop-invariants [enabled]
I can definitely see why this is confusing.
Richard
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question about knowing when optimization options are used
2020-03-17 12:22 ` Richard Sandiford
@ 2020-03-18 20:15 ` Segher Boessenkool
0 siblings, 0 replies; 13+ messages in thread
From: Segher Boessenkool @ 2020-03-18 20:15 UTC (permalink / raw)
To: Shrader, David Lee, gcc-help, richard.sandiford
On Tue, Mar 17, 2020 at 12:22:07PM +0000, Richard Sandiford wrote:
> Segher Boessenkool <segher@kernel.crashing.org> writes:
> > On Mon, Mar 16, 2020 at 11:14:25PM +0000, Shrader, David Lee via Gcc-help wrote:
> >> Most optimizations are only enabled if an -O level is set on the command line. Otherwise they are disabled, even if individual optimization flags are specified.
> >
> > Yes.
> >
> >> The man page says to use `-Q --help=optimizers` to find out what is turned on for the different -O levels as configure-time options can make things different from the defaults shown later in that man page. However, I have found that, even when using -O0, I can turn on optimization options, at least according to the help output:
> >
> > You can enable the *flags*, sure, but with -O0 those flags do not do
> > anything. Exactly as the text above says? The "even if" part.
>
> I think David's the right that the wording isn't clear though.
Oh yes, I didn't mean to suggest it is perfect as is, sorry.
> The documentation sets up a contrast between an option being "enabled"
> or merely "specified", with "enabled" meaning something like "have an
> effect". But the quoted output then undermines that by using "enabled"
> for what the documentation calls "specified":
>
> $> gcc -Q --help=optimizers -fmove-loop-invariants | grep "\-fmove-loop-invariants"
> -fmove-loop-invariants [enabled]
>
> I can definitely see why this is confusing.
Yeah. Help output is not documentation, but if they aren't in agreement,
what is a user to do? :-(
Does anyone have proposed improved wording, etc.?
Segher
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question about knowing when optimization options are used
2020-03-16 23:34 ` Segher Boessenkool
2020-03-16 23:55 ` [EXTERNAL] " Shrader, David Lee
2020-03-17 12:22 ` Richard Sandiford
@ 2020-03-18 17:44 ` mark_at_yahoo
2020-03-18 21:24 ` Segher Boessenkool
2020-03-19 14:17 ` Jonathan Wakely
3 siblings, 1 reply; 13+ messages in thread
From: mark_at_yahoo @ 2020-03-18 17:44 UTC (permalink / raw)
To: gcc-help
On 3/16/20 4:34 PM, Segher Boessenkool wrote:
> You can enable the *flags*, sure, but with -O0 those flags do not do
> anything. Exactly as the text above says? The "even if" part.
(Meta-response: I tried sending the following via nabble.com approx. 40
hours ago and it seems not to have gotten through. Apologies if this
eventually shows up as a duplicate.)
Sorry to question this, but my experience has been otherwise. I haven't
tried it in a while (probably last did on an older release) but at least
with gcc-arm, doing:
-O0 \
-fbranch-count-reg \
-fcombine-stack-adjustments \
-fcompare-elim \
-fcprop-registers \
<long list of other flags deleted>
*did* do something different than just "-O0".
The above was part of my semi-successful attempt to solve the following
problem:
1) I'm compiling ARM code for an embedded microcontroller with very
limited memory
2) My code includes header files with literally thousands (no
exaggeration) of "static const int ..."s
3) The code (intentionally) uses only a handful of the consts
4) If compiled "-O1", no memory is allocated for the thousands of consts
(not even the few that are used)
5) If compiled "-O0" memory is allocated for each const -- far more
memory than is available
6) "-O0" executables are much easier to debug at the machine instruction
level (sometimes necessary on microcontrollers)
Can anyone suggest a minimal set of "-f<options>"s to add to -O0 which
will do what I want, i.e. no code optimizations, but also no memory
allocated for the consts?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question about knowing when optimization options are used
2020-03-18 17:44 ` mark_at_yahoo
@ 2020-03-18 21:24 ` Segher Boessenkool
0 siblings, 0 replies; 13+ messages in thread
From: Segher Boessenkool @ 2020-03-18 21:24 UTC (permalink / raw)
To: mark_at_yahoo; +Cc: gcc-help
On Wed, Mar 18, 2020 at 10:44:09AM -0700, mark_at_yahoo via Gcc-help wrote:
> On 3/16/20 4:34 PM, Segher Boessenkool wrote:
> >You can enable the *flags*, sure, but with -O0 those flags do not do
> >anything. Exactly as the text above says? The "even if" part.
> Sorry to question this, but my experience has been otherwise.
From the manual again:
Most optimizations are completely disabled at '-O0' or if an '-O' level
is not set on the command line, even if individual optimization flags
are specified. Similarly, '-Og' suppresses many optimization passes.
> I haven't
> tried it in a while (probably last did on an older release) but at least
> with gcc-arm, doing:
>
> -O0 \
> -fbranch-count-reg \
> -fcombine-stack-adjustments \
> -fcompare-elim \
> -fcprop-registers \
> <long list of other flags deleted>
>
> *did* do something different than just "-O0".
It might be interesting to see which compiler flag(s) you see any
differences with.
> 2) My code includes header files with literally thousands (no
> exaggeration) of "static const int ..."s
> 3) The code (intentionally) uses only a handful of the consts
> 4) If compiled "-O1", no memory is allocated for the thousands of consts
> (not even the few that are used)
> 5) If compiled "-O0" memory is allocated for each const -- far more
> memory than is available
> 6) "-O0" executables are much easier to debug at the machine instruction
> level (sometimes necessary on microcontrollers)
>
> Can anyone suggest a minimal set of "-f<options>"s to add to -O0 which
> will do what I want, i.e. no code optimizations, but also no memory
> allocated for the consts?
Try -Og instead? It is mostly like -O1, but almost all debugging should
work fine with it (as the option name itself suggests :-) )
Segher
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: question about knowing when optimization options are used
2020-03-16 23:34 ` Segher Boessenkool
` (2 preceding siblings ...)
2020-03-18 17:44 ` mark_at_yahoo
@ 2020-03-19 14:17 ` Jonathan Wakely
3 siblings, 0 replies; 13+ messages in thread
From: Jonathan Wakely @ 2020-03-19 14:17 UTC (permalink / raw)
To: Shrader, David Lee; +Cc: gcc-help
On Mon, 16 Mar 2020 at 23:35, Segher Boessenkool wrote:
>
> On Mon, Mar 16, 2020 at 11:14:25PM +0000, Shrader, David Lee via Gcc-help wrote:
> > Most optimizations are only enabled if an -O level is set on the command line. Otherwise they are disabled, even if individual optimization flags are specified.
>
> Yes.
>
> > The man page says to use `-Q --help=optimizers` to find out what is turned on for the different -O levels as configure-time options can make things different from the defaults shown later in that man page. However, I have found that, even when using -O0, I can turn on optimization options, at least according to the help output:
>
> You can enable the *flags*, sure, but with -O0 those flags do not do
> anything. Exactly as the text above says? The "even if" part.
See also https://gcc.gnu.org/wiki/FAQ#optimization-options
^ permalink raw reply [flat|nested] 13+ messages in thread