<div dir="ltr"><div>Hello,</div><div><br></div><div>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. <br></div><div><br></div><div>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?</div><div><br></div><div>So my question is:</div><div>(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 developer's perspective?<br></div><div>(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?</div><div><br></div><div>Thanks!</div><div>Haoran<br></div><div><br></div></div>