Re: In GCC 10.2, -O2 optimization enables more than docs suggest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 20 Jan 2021, 16:54 mark_at_yahoo via Gcc-help, <gcc-help@xxxxxxxxxxx>
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. ;)
>



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux