https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104420
Bug ID: 104420 Summary: [12 Regression] Inconsistent checks for X * 0.0 optimization Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- (from a comment in PR 104389) /* Maybe fold x * 0 to 0. The expressions aren't the same when x is NaN, since x * 0 is also NaN. Nor are they the same in modes with signed zeros, since multiplying a negative value by 0 gives -0, not +0. Nor when x is +-Inf, since x * 0 is NaN. */ (simplify (mult @0 real_zerop@1) (if (!tree_expr_maybe_nan_p (@0) && (!HONOR_NANS (type) || !tree_expr_maybe_infinite_p (@0)) && !tree_expr_maybe_real_minus_zero_p (@0) && !tree_expr_maybe_real_minus_zero_p (@1)) @1)) Notice how the comment talks about @0 being a "negative value" while the code says "!tree_expr_maybe_real_minus_zero_p (@0)", which is not at all the same thing. Because tree_expr_maybe_real_minus_zero_p is rather weak, it does not trigger so often, but still: double f(int a){ return a*0.; } is optimized to "return 0.;" whereas f(-42) should return -0.