Re: [match.pd PATCH] PR tree-optimization/126467: 0.0-x -> -x vs. signed zeros.
Andrea Pinski <[email protected]> Thu, 6 Aug 2026 23:07:52 -0700
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <CALvbMcCjX+v9ovyNzqfykdnr6NTEU=aj25U+AacRG20TLhNrZQ@mail.gmail.com> |
On Wed, Aug 5, 2026 at 1:06 AM Roger Sayle <[email protected]> wrote: > > > This is my proposed solution to PR tree-optimization/126467, where we're > inappropriately converting 0.0 - x to -x when we honor IEEE signed zeros. > This transformation is valid with -Ofast, but by default +0.0 - +0.0 > should return +0.0, but -(+0.0) is -0.0. Likewise when x is NaN, 0.0 - x > may change the payload, but -x is guaranteed not to. My fix is to > separate the logic for this transformation from that for FP addition. > > Technically, we could do slightly better by introducing a > tree_expr_negative_p (complementing and mutually recursive with the > existing tree_expr_nonnegative_p), but that's a bigger change and > less suitable for backporting to release branches, i.e. a follow-up. > > I agree with Alexander Monakov that an alternate fix might be to > correctly reuse the existing fold_real_zero_addition_p functionality > by constructing and garbage collecting a NEGATE_EXPR tree on each call, > but this seems a little less efficient. > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=unix{-m32} > with no new failures. Ok for mainline? `!HONOR_NANS (type) || !tree_expr_maybe_nan_p (@1)` You don't need the HONOR_NANS part here since tree_expr_maybe_nan_p already handles that. Otherwise ok. Thanks, Andrea > > > 2026-08-05 Roger Sayle <[email protected]> > > gcc/ChangeLog > PR tree-optimization/126467 > * match.pd (0.0 - x -> -x): Update the conditions under which > the transformation is performed, disallowing x = +0.0 when we > honor signed zeros. > > gcc/testsuite/ChangeLog > PR tree-optimization/126467 > * gcc.dg/pr126467-1.c: New test case. > * gcc.dg/pr126467-2.c: Likewise. > * gcc.dg/pr96392.c: Fix incorrect test case. >