[LLVMdev] Disabling certain optimizations at -O1?

Renato Golin renato.golin at linaro.org
Thu Nov 28 05:11:27 PST 2013


On 28 November 2013 00:00, Robinson, Paul
<Paul_Robinson at playstation.sony.com> wrote:
> In my experience, to a first approximation, anything
> that changes the CFG or that reorders generated code beyond source
> statement boundaries is likely to make things more difficult for the
> debugger.

I agree.


> Okay.  I worked on compilers where -O1 was the default, actually, and
> it was "generally fast enough" but still very easy to produce very
> good debug info.

Me too, but if you search the meaning of that, it's actually to
maintain the debug illusion. You want to make it simple enough for the
user, the default should be a local minimum for all three functions:
speed, simplicity, debugability.

$ cc -g foo.c -o foo
$ dbg foo

It doesn't get simpler than that, if foo is "fast enough". But for the
debug session to *also* be simple, you must do your best to keep
program order on the resulting binary and to generate the best debug
info you possibly can.

That's -O1.

There are many local minima for all three functions, so different
compilers have different choices, but that, IMO, is the Holly Grail of
O1.


> I see what you're driving at although I'd quibble about two things.
> - "Debug" is kind of overloaded, maybe "Simple" would express the right
> semantic without being so ambiguous (avoid the -g thing!).

I agree. Debug is specific. Simple is generic.


> - I wonder whether Simple/Speed/Space are better modeled as a single
> three-way setting and not as flags.  Is it sensible to have more than
> one of those three on at the same time?  I wouldn't think so...

Yes, the idea is that they are mutually exclusive. What that means
underneath the bonnet doesn't matter, but as a *user* decision, it's
quite simple and powerful.

Just for context, this conversation started after a few emails were
sent asking the same question: In which opt level do I put my new
pass? What I found is that people have different concepts of what each
level should be, and that's because every other compiler take the
matters slightly different from all others. If the policy is clear,
than we can create a map of opt levels for passes that most people
agree.

cheers,
--renato



More information about the llvm-dev mailing list