Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

fine-tune the -Og optimization level for better debugging experience #20764

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR20765
Status CONFIRMED
Importance P enhancement
Reported by Huang Li (softwarego@163.com)
Reported on 2014-08-27 03:04:12 -0700
Last modified on 2020-08-06 22:00:52 -0700
Version unspecified
Hardware All All
CC agenda2010@grueninger.de, anton@korobeynikov.info, austinenglish@gmail.com, davidfromonline@gmail.com, dberlin@dberlin.org, dblaikie@gmail.com, echristo@gmail.com, greg.bedwell@sony.com, halilsen@gmail.com, jsweval@arxan.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, noloader@gmail.com, paul_robinson@playstation.sony.com, rengolin@gmail.com, sylvestre@debian.org, trass3r@gmail.com, yuanfang.chen@sony.com, zeratul976@hotmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

In GCC Doc, there is an optimization level called -Og available.

-Og Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

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:

error: invalid integral value 'g' in '-Og'

It appears that clang doesn't understand -Og at all.

Quuxplusone commented 9 years ago

_Bug 23187 has been marked as a duplicate of this bug._

Quuxplusone commented 9 years ago
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.
Quuxplusone commented 9 years ago
(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.
Quuxplusone commented 9 years ago
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.
Quuxplusone commented 9 years ago
(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.
Quuxplusone commented 9 years ago
(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.
Quuxplusone commented 7 years ago

Working on it.

Quuxplusone commented 7 years ago
(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.
Quuxplusone commented 7 years ago
Paul, for now, just -O1 == -Og
https://reviews.llvm.org/D24998

happy to get better suggestions!
Quuxplusone commented 7 years ago
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)
Quuxplusone commented 7 years ago
(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
Quuxplusone commented 4 years ago
(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.
Quuxplusone commented 4 years ago

I am actively working on this :)

Quuxplusone commented 4 years ago

echristo's got some interest in tuning -O1 for debuggable, FWIW

Quuxplusone commented 4 years ago

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 ?

Quuxplusone commented 4 years ago

Both :)