[LLVMdev] [cfe-dev] RFC: Codifying (but not formalizing) the optimization levels in LLVM and Clang

dag at cray.com dag at cray.com
Mon Jan 14 10:34:55 PST 2013


Chandler Carruth <chandlerc at gmail.com> writes:

> 4) Good, well-balanced optimizations, or '-O2'
> - Attribute: opt (new attribute)

Since all other levels have a qualifier, I'd suggest we do that here as
well.  Perhaps balancedopt?

> 5) Optimize to the max or '-O3'
> - Attribute: maxopt (new attribute)
> - Goal: produce the fastest binary possible.

> This level should always produce binaries at least as fast as opt, but
> they might be faster at the cost of them being larger and taking more
> time to compile.

That's almost impossible to achieve if you include things like
vectorization.  It is often difficult to know statically whether
vectorization will help or harm.  One can do runtime code selection but
that has its own costs and can be slower than O2 in some cases.

I simply don't think it's a useful or achieveable guarantee.  It's a
good goal but I would be against making it a reuiqrement as it will
severely limit what we do at O3 over O2.

FWIW, the Cray compiler considers O3 to be "try to make it as fast as
possible without unreasonably increasing compile time" but does not
guarantee it absolutely will be faster than -O2.  We have -Oaggress for
"pull out all the stops, take days to compile the code and you get what
you get."  :)

> A final note: I would like to remove all other variations on the '-O'
> flag. That includes the really strange '-O4' behavior. Whether the
> compilation is LTO should be an orthogonal decision to the particular
> level of optimization, and we have -flto to achieve this.

Agreed.

                                     -David



More information about the llvm-dev mailing list