public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: mark_at_yahoo <markrubn@yahoo.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: In GCC 10.2, -O2 optimization enables more than docs suggest
Date: Wed, 20 Jan 2021 18:50:58 +0000	[thread overview]
Message-ID: <CAH6eHdTsMReT4t73EV_EzkJRLVc8umqd78o5fRj61_vfCFiZYA@mail.gmail.com> (raw)
In-Reply-To: <b0b1b5a2-ed42-7977-d191-f11185c362cf@yahoo.com>

On Wed, 20 Jan 2021, 16:54 mark_at_yahoo via Gcc-help, <gcc-help@gcc.gnu.org>
wrote:

> On 1/20/21 7:56 AM, Richard Earnshaw via Gcc-help wrote:
> > On 16/01/2021 20:48, Brent Roman wrote:
> >> Here's an example of a gcc invocation with -O2 followed by disabling all
> >> the -O2 specific optimizations:
> >> ...
> >
> > Sorry, it's not as simple as that.  There are places in the compiler
> > where the optimization level (O1, O2, O3) is just tested with something
> like
> >
> >    if (optimize >= level)
> >
> > for some level.
> >
> > R.
> >
>
> Just chiming in with an opinion here. I've had the same problem and came
> to the same conclusion ("-f" options do not fully replace/override "-O")
> although I didn't know the compiler source was that explicit about it
> (thanks for the info).
>
> I realize this is very unlikely to change but find the situation
> unfortunate. My use-case is with the GNU Arm Embedded Toolchain port of
> GCC and my https://github.com/thanks4opensource/regbits development
> system. The latter creates C++ header files with literally thousands of
> constexpr objects of which only a handful are used in a typical program.
> If compiled O1 or above, the linker only allocates storage for the
> objects that are used. At O0 it allocates all of them which makes the
> resulting binary far too large to fit in a typical embedded processor's
> memory space. But O0 is very useful for assembly-level debugging in GDB
> (often required in embedded development) because the generated code is
> much simpler and easier to correlate with the original C++ source.
>
> I've only had limited success coming up with a set of -f options to add
> to O0 to eliminate the unused objects but retain the un-optimized binary
> code.


That's a different situation though. With -O0 **NO** optimization is done,
at all. Any -f options for optimization passes are ignored entirely.

The difference between -O1 and -O2 is the set of -f flags that differ, and
some specific checks for >= -O2. But the difference between -O0 and -O1 is
the difference between zero and non-zero. Completely off, or on.

The above explains why, but it would be nice if the -O options
> really were just a set of -f ones and users could customize to their
> needs. Without implementing my specific "-O0.5" option. ;)
>

  reply	other threads:[~2021-01-20 18:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16 20:48 Brent Roman
2021-01-20 15:56 ` Richard Earnshaw
2021-01-20 16:53   ` mark_at_yahoo
2021-01-20 18:50     ` Jonathan Wakely [this message]
2021-01-20 19:06       ` mark_at_yahoo
2021-01-20 19:44         ` Jonathan Wakely
2021-01-20 20:45           ` mark_at_yahoo
2021-01-20 21:17     ` David Brown
2021-01-21  3:53       ` mark_at_yahoo
2021-01-21  9:02         ` David Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdTsMReT4t73EV_EzkJRLVc8umqd78o5fRj61_vfCFiZYA@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=markrubn@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).