https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110305
Bug ID: 110305 Summary: Incorrect optimization with -O3 -fsignaling-nans -fno-signed-zeros Product: gcc Version: og12 (devel/omp/gcc-12) Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: tkisuki at tachyum dot com Target Milestone: --- float f(float a) { return a + 0.0f; } Compiling the above code with -O3 -fsignaling-nans -fno-signed-zeros simplifies 'a + 0' to 'a'. It seems '-fsignaling-nans' is not considered for this simplification. Simplification is done by simplify_context::simplify_binary_operation_1() function in gcc/simplify-rtx.cc. '-fsignaling-nans' is experimental, but can the condition also check !HONOR_SNANS(mode)? --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -2698,7 +2698,8 @@ simplify_context::simplify_binary_operation_1 (rtx_code code, when x is NaN, infinite, or finite and nonzero. They aren't when x is -0 and the rounding mode is not towards -infinity, since (-0) + 0 is then 0. */ - if (!HONOR_SIGNED_ZEROS (mode) && trueop1 == CONST0_RTX (mode)) + if (!HONOR_SIGNED_ZEROS (mode) && !HONOR_SNANS (mode) + && trueop1 == CONST0_RTX (mode)) return op0;