On Thu, 17 Nov 2022, Aldy Hernandez via Gcc-patches wrote: > So... is the optimization wrong? Are we not allowed to substitute > that NAN if we know it's gonna happen? Should we also allow F F F F F > in the test? Or something else?
This seems like the usual ambiguity about what transformations -ftrapping-math (on by default) is meant to prevent. Generally it's understood to prevent transformations that add *or remove* exceptions, so folding a case that raises "invalid" to a NaN (with "invalid" no longer raised) is invalid with -ftrapping-math. But that doesn't tend to be applied if the operation raising the exceptions has a result that is otherwise unused - in such a case the operation may still be removed completely (the exception isn't properly treated as a side effect to avoid dead code elimination; cf. Marc Glisse's -ffenv-access patches from August 2020). And it may often also not be applied to "inexact". There have been various past discussions of possible ways to split up the different effects of options such as -ftrapping-math into finer-grained options allowing more control of what transformations are permitted - see e.g. <https://gcc.gnu.org/pipermail/gcc-patches/2021-September/thread.html#580252> and bug 54192. There is also the question in that context of which sub-options should be enabled by default at all. -- Joseph S. Myers jos...@codesourcery.com