https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61441
--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> --- On Thu, 13 Aug 2015, ssaraswati at gmail dot com wrote: > With -fno-signaling-nans (which is the default), we need to fix the ccp so > that > the sNaN is converted to qNaN when the value is propagated. With -fno-signaling-nans we don't really care about the result value. > With -fsignaling-nans, we need to ensure that we disable the folding since it > reduces the number of exceptions visible with sNaNs. I notice that even if I More precisely, exceptions are relevant with -fsignaling-nans -ftrapping-math but even with -fno-trapping-math it's still visible if the result is wrongly a sNaN instead of a qNaN. (-ftrapping-math is the default. It's not clear there's any use for -fsignaling-nans -fno-trapping-math. But -fsignaling-nans is the option that says there may be signaling NaN arguments, and -ftrapping-math is the option that says we care about exceptions.) The *number* of exceptions isn't relevant, only the set raised at any point (e.g. function call) where the raised exceptions may be tested or modified; it's valid to change one nonzero number of times raising a given exception between two such points to a different nonzero number of times raising that exception. > disable ccp, other optimizations like dead code elimination with cddce also > needs to be disabled. Let me know if you agree. I'm sure there are lots of optimizations that wrongly discard exceptions, whether for signaling NaNs or other operands. Roughly, the present -ftrapping-math seems to be implemented as meaning that an expression shouldn't be transformed to change the exceptions raised, but exceptions aren't treated as side effects so it can still be discarded if apparently unused, or moved past code that might test or modify exceptions. Something stricter that actually follows Annex F would treat exceptions more like side effects and eliminate a lot of code movement / dead code removal. It might be less suitable for the default compilation mode, however. I expect there are plenty of bugs even with that more limited description of what -ftrapping-math tries to do.