question about knowing when optimization options are used

Wed Mar 18 17:44:09 GMT 2020

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

More information about the Gcc-help mailing list