https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112449
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jsm28 at gcc dot gnu.org, | |rguenth at gcc dot gnu.org --- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> --- I think if you can reproduce the issue with -fsignaling-nans (which defaults to off) then I would consider this to be an implementation issue. The GCC middle-end shouldn't clang to contradicting wording in the C standard here. In particular we say @opindex fsignaling-nans @item -fsignaling-nans Compile code assuming that IEEE signaling NaNs may generate user-visible traps during floating-point operations. Setting this option disables optimizations that may change the number of exceptions visible with signaling NaNs. This option implies @option{-ftrapping-math}. Changing tem = x * 1.0 to tem = x would possibly change the number of observed traps if tem is used more than once. OTOH below we also say This option is experimental and does not currently guarantee to disable all GCC optimizations that affect signaling NaN behavior. so bugs in this area are expected (but they are still bugs IMHO). CCing Joseph for clarification. Note a quick check with double foo (double x) { return x * 1.0; } and -O2 -fsignaling-nans shows the multiplication is preserved (on x86_64), so is your example in godbolt where you fail to specify -fsignaling-nans. I agree the documentation is maybe not entirely clear about the effect.