This is an archive of the discontinued LLVM Phabricator instance.

Add a new optimization option -Og
ClosedPublic

Authored by sylvestre.ledru on Sep 27 2016, 8:41 PM.

Diff Detail

Event Timeline

sylvestre.ledru retitled this revision from to Add a new optimization option -Og .
sylvestre.ledru updated this object.
sylvestre.ledru added a reviewer: rengolin.
sylvestre.ledru added a subscriber: cfe-commits.

Please include full context with your diff.

lib/Frontend/CompilerInvocation.cpp
101–103

Please clang-format this.

with the full context + clang format

Hi Sylvestre,

Paul's comments on the bug are still pertinent: -Og is not the same as -O1.

-Og means for "optimised for debuggers" which is short for "preserve the debug illusion without bloating the code". This is not at all what -O1 is, even though they're used indistinguishably via -O1 -g.

As a stop-gap, I guess having -Og == -O1 would stop errors from being reported, but if we could do a quick assessment on the list to make sure this has the expected semantics (and adding a full new option if not), would be the best way forward.

I'm adding a few debug folks here, in hope they have a better idea (and would add more folks, if necessary). :)

cheers,
--renato

dblaikie added inline comments.Oct 4 2016, 9:27 AM
test/Driver/debug-options.c
21–22 ↗(On Diff #72759)

I don't think we need this test case: -Og doesn't actually have anything to do with -g mechanically speaking, so there's no need to test them together.

I'd probably go find wherever -O1 is tested in the driver, and test -Og there.

As Renato points out, this addresses the user experience of tripping over the lack of -Og, however it does not really address the intent of PR20765 which is to provide a mode of optimizations that don't particularly interfere with debugging.
Eventually someone needs to take on the project of "proper -Og" which might or might not result in -Og still matching -O1.
I am not opposed to starting out this way, but don't close the PR.

If we later get user complaints about how -Og interferes with debugging, well, then we'll have actual use-cases to work from, which is extremely helpful for this sort of optimization tuning.

test/Preprocessor/init.c
208

check-prefix O1? Then you don't need the Og: and Og-NOT: lines.

Looking into what optimisations would be relevant to -Og (or rather what optimisation should be omitted because they are too disruptive to the debug experience) is something that I have on my road-map as something to look into and gather feedback on.

I agree that this should be considered as just the starting point for enabling a fully functional -Og option.

RKSimon added a subscriber: RKSimon.Oct 5 2016, 3:31 AM
sylvestre.ledru edited edge metadata.
rengolin accepted this revision.Nov 11 2016, 9:27 AM
rengolin edited edge metadata.

I agree with Keith. This is a starting point, not a final destination.

As we evolve this, we can start looking at better ways to improve the debug illusion, but right now, O1 is probably the best thing to do.

LGTM, thanks!

This revision is now accepted and ready to land.Nov 11 2016, 9:27 AM

This seems to have hit a recent Xcode toolchain (Xcode 9.1 ?).

Xcode now complains that "[app name] was compiled with optimization - stepping may behave oddly; variables may not be available.", when launching a debug session, which seems to be the case, debugging is all over the place :)

Reproduced on both macOS and iOS targets.

See https://codereview.qt-project.org/#/c/212142/

This seems to have hit a recent Xcode toolchain (Xcode 9.1 ?).

Xcode now complains that "[app name] was compiled with optimization - stepping may behave oddly; variables may not be available.", when launching a debug session, which seems to be the case, debugging is all over the place :)

LLDB prints this warning whenever LLVM marks a compile unit with DW_AT_optimized (which LLVM does for everything but -O0).

Reproduced on both macOS and iOS targets.

See https://codereview.qt-project.org/#/c/212142/