public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Roger Sayle <roger@nextmovesoftware.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR middle-end/98420: Don't fold x - x to 0.0 with -frounding-math
Date: Fri, 11 Mar 2022 12:16:21 +0100	[thread overview]
Message-ID: <CAFiYyc0qdrV2b_hHdhuA21vV3iuCAJOs-K93kcwDeNH7tdhkLQ@mail.gmail.com> (raw)
In-Reply-To: <00f501d834d6$ef7e30e0$ce7a92a0$@nextmovesoftware.com>

On Fri, Mar 11, 2022 at 12:31 AM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch addresses PR middle-end/98420, which is inappropriate constant
> folding of x - x to 0.0 (in match.pd) when -frounding-math is specified.
> Specifically, x - x may be -0.0 with FE_DOWNWARD as the rounding mode.
>
> To summarize, the desired IEEE behaviour, x - x for floating point x,
> (1) can't be folded to 0.0 by default, due to the possibility of NaN or Inf
> (2) can be folded to 0.0 with -ffinite-math-only
> (3) can't be folded to 0.0 with -ffinite-math-only -frounding-math
> (4) can be folded with -ffinite-math-only -frounding-math -fno-signed-zeros
>
> Technically, this is a regression from GCC 4.1 (according to godbolt.org)
> so hopefully this patch is suitable during stage4.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check with no new failures.  Ok for mainline?

+         && !tree_expr_maybe_infinite_p (@0)
+         && (!flag_rounding_math || !HONOR_SIGNED_ZEROS (type))))
   { build_zero_cst (type); }))

HONOR_SIGN_DEPENDENT_ROUNDING (type) instead of flag_rounding_math?

OK with that change.

Richard.

>
> 2022-03-10  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
>         PR middle-end/98420
>         * match.pd (minus @0 @0): Additional checks for -fno-rounding-math
>         (the defaut) or -fno-signed-zeros.
>
> gcc/testsuite/ChangeLog
>         PR middle-end/98420
>         * gcc.dg/pr98420.c: New test case.
>
>
> Thanks in advance,
> Roger
> --
>

      reply	other threads:[~2022-03-11 11:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10 23:31 Roger Sayle
2022-03-11 11:16 ` Richard Biener [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc0qdrV2b_hHdhuA21vV3iuCAJOs-K93kcwDeNH7tdhkLQ@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=roger@nextmovesoftware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).