[llvm-dev] Exceptions and performance
Haoran Xu via llvm-dev
llvm-dev at lists.llvm.org
Thu Aug 13 14:59:15 PDT 2020
I have been long taught that exceptions are considered the bad parts in the
design of C++ language, and one should avoid using it since it's hard to
write exception-safe code (I have no disagreement on this part) and it
impedes compiler optimization.
However, when recently I dig into the implementation of exception handling
mechanism in LLVM recently, my impression is that using exceptions should
instead improve performance (in the common case that no exception is thrown
out), compared with the traditional approach of returning an error code in
every function that can fail: no error-code-checking logic is executed in
the fastpath, and error-handling code are moved from the main binary to the
exception table, so the CPU is doing less work, and also instruction cache
locality should be improved. Is my understanding correct?
So my question is:
(1) Is the argument that 'exception hurts compiler optimization, and should
not be used in perf-sensitive code' outdated now? Or more generally, what
are the pros and cons of using exception vs error code, from a LLVM backend
(2) In current LLVM design, is there still any optimization that is
prevented by using exceptions? Or is the current LLVM already able to
provide the same optimization quality for code using exceptions, compared
with code that does not?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev