Open Quuxplusone opened 10 years ago
_Bug 23187 has been marked as a duplicate of this bug._
According to Jonathan Wakely on the GCC mailing list, we can use the following
to see what optimizations are enabled with -Og:
{gcc|g++} -Q -Og --help=optimizers
See "What optimizations are included in -Og?", https://gcc.gnu.org/ml/gcc-
help/2015-04/msg00064.html.
It might be useful if Clang wants to resemble the behavior of GCC. Or, it may
offer ideas for optimizations that can be taken in a debug build without
affecting the debug experience.
(In reply to comment #0)
> In [GCC Doc](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html),
> there is an optimization level called -Og available.
>
> >-Og
> ...
> It appears that clang doesn't understand -Og at all.
The issue is present with Clang/LLVM 3.6.
My habit has been to use -O1, which for gcc turns out to be trivially
different from -Og. Diffing the gcc help lists for -O1 and -Og shows
-finline-functions-called-once and -ftree-sra are enabled for -O1 but
disabled for -Og.
I don't know that anybody has tried to assess the debugging experience
with Clang's -O1, but I'd be in favor of fine-tuning -O1 to be a good
experience and then just take -Og as a synonym of -O1.
(In reply to comment #4)
> My habit has been to use -O1, which for gcc turns out to be trivially
> different from -Og.
Yes, me too until -Og.
> Diffing the gcc help lists for -O1 and -Og shows
> -finline-functions-called-once and -ftree-sra are enabled for -O1 but
> disabled for -Og.
>
> I don't know that anybody has tried to assess the debugging experience
> with Clang's -O1, but I'd be in favor of fine-tuning -O1 to be a good
> experience and then just take -Og as a synonym of -O1.
I think an underlying user goal or desire is to ensure some sort on analysis
(i.e., for example, -Wstrict-overflow requires analysis to work/warn), but
minimize the "optimized out" messages under the debugger.
I think one of the goals for the project is to ensure Clang can consume -Og.
If Clang maps -Og to a modified -O1, then that should be sufficient to meet
both goals. I'd call it a win.
(In reply to comment #5)
>
> I think an underlying user goal or desire is to ensure some sort on analysis
> (i.e., for example, -Wstrict-overflow requires analysis to work/warn), but
> minimize the "optimized out" messages under the debugger.
Paul - this might also be something to think about as you formulate an
approach. "value optimized out" is pretty common under debuggers, but
frustrating at times. To avoid it, we use -g3 to ensure GCC includes symbolic
defines.
There's a difference between Clang and GCC here, but I don't recall what it is.
Maybe something like under Clang, there is no -g3 per se; its really just -g2.
(My apologies if I got that wrong).
So whatever mapping that could occur from -Ox to -Oy, try to ensure the
symbolic defines are preserved or available under the debugger.
Working on it.
(In reply to comment #7)
> Working on it.
With what semantics? And probably should bring it up on llvm-dev
as various debug-info stakeholders are not cc'd on this bug.
Paul, for now, just -O1 == -Og
https://reviews.llvm.org/D24998
happy to get better suggestions!
Implemented and landed the change in https://reviews.llvm.org/D24998
We agreed on keeping the bug open as we may want to add/remove optimizations in
the future (happy to do it if someone has suggestions)
(In reply to comment #9)
> Paul, for now, just -O1 == -Og
> https://reviews.llvm.org/D24998
>
> happy to get better suggestions!
I thought the following stackoverflow answer might be of use. It explains the
differences between -O1 and -Og
http://stackoverflow.com/questions/12970596/gcc-4-8-does-og-imply-g/27076307#27076307
(In reply to Paul Robinson from comment #4)
> My habit has been to use -O1, which for gcc turns out to be trivially
> different from -Og. Diffing the gcc help lists for -O1 and -Og shows
> -finline-functions-called-once and -ftree-sra are enabled for -O1 but
> disabled for -Og.
The difference has grown larger by now: https://godbolt.org/z/6fasjr
> I don't know that anybody has tried to assess the debugging experience
> with Clang's -O1, but I'd be in favor of fine-tuning -O1 to be a good
> experience and then just take -Og as a synonym of -O1.
I see plenty of <optimized out>s with clang-10 -Og.
I am actively working on this :)
echristo's got some interest in tuning -O1 for debuggable, FWIW
By creating a separate pipeline or by improving the debug info similar to efforts like https://llvm.org/devmtg/2019-04/slides/TechTalk-Prica-Improving_LLVM_DebugInfo.pdf ?
Both :)
In GCC Doc, there is an optimization level called -Og available.
There are a few projects and some users (like me) which like to debug with the
-Og
option.In OS X XCode Command Line tools, /usr/bin/gcc is simply a hard link or possibly a copy of /usr/bin/clang. When I tried to use the -Og option, I got:
It appears that clang doesn't understand -Og at all.