[cfe-dev] Optimizations around noexcept()

Nicola Gigante nicola.gigante at gmail.com
Fri Oct 11 07:50:41 PDT 2013


Hello.

A couple of question regarding how clang can optimize code with the C++11 noexcept specification.

1) If I understand correctly, if zero cost exceptions are used, the speed of the call should be the same
even if the compiler does know that the function doesn't throw. However, does this information enable
optimizations around the function call? Which kind of optimizations can be enabled with this assumption?

2) I suppose the noexcept specification is lowered to the nounwind LLVM attribute, correct me if this is wrong or
incomplete. However, I've seen llvm correctly adding the nounwind attribute to functions that it can prove don't throw.
Thus, is noexcept worth something in terms of performance (I'm not talking about maintainability here) if all the function code
can be seen by the call site and nounwind can be inferred? In the case of a header only template library, where all the code
can be seen in each compilation unit, this is the common case (but I suppose the same applies to any other kind of code if compiled
with -O4).

Thank you very much,
Nicola



More information about the cfe-dev mailing list