So GCC has always defaulted to -ftrapping-math but that has always come with many issues. Especially if we go by Joseph's definition of the flag (from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53805#c4 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54192): ``` As per my previous comment, -ftrapping-math currently affects (or
might affect if fully implemented) several different things: * Disallowing code transformations that cause some code to raise more exception flags than it would have before. * Disallowing code transformations that cause some code to raise fewer exception flags than it would have before. * Ensuring the code generated allows for possible non-local control flow from exception traps raised by floating-point operations (this is the part where -fnon-call-exceptions might be relevant). * Disallowing code transformations that might affect whether an exact underflow exception occurs in some code (not observable through exception flags, is observable through trap handlers). * Ensuring floating-point operations that might raise exception flags are not removed, or moved past code (asms or function calls) that might read or modify the exception flag state (not implemented, modulo Marc Glisse's -ffenv-access patches from August 2020) ``` The second point is something which GCC tries to do in some cases but in many others GCC removes the statements that would/could raise exception flags. This is especially true when the statement would be DCEd as unused. It also has been in this situation since at least 3.4.0 (maybe longer). So my proposal is turn off trapping-math by default for the C and C++ front-end and also file a bug report for all of the cases where -ftrapping-math is removing the statements that it should not be removed. Note clang/LLVM defaults to -fno-trapping-math and so comparisons between GCC and LLVM sometimes will not be totally fair. And yes we are getting more and more cases where the exception flags matter; e.g. vectorizer. So there huge difference starting to show up in performance between -fno-trapping-math and -ftrapping-math now too. Thanks, Andrea
