public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [PATCH] [PR tree-optimization/107355] Handle NANs in abs range-op entry.
Date: Mon, 24 Oct 2022 15:34:31 +0200	[thread overview]
Message-ID: <CAGm3qMXX8FbLmJdDsWb2KQcZQq3S702SdCiAyNfWZHS7_1MXjw@mail.gmail.com> (raw)
In-Reply-To: <20221024133316.33026-1-aldyh@redhat.com>

Tested on x86-64 Linux.

Pushed.

On Mon, Oct 24, 2022 at 3:33 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> The problem here is that the threader is coming up with a path where
> the only valid result is a NAN.  When the abs op1_range entry is
> trying to add the negative posibility, it attempts to get the bounds
> of the working range.  NANs don't have bounds so they need to be
> special cased.
>
>         PR tree-optimization/107355
>
> gcc/ChangeLog:
>
>         * range-op-float.cc (foperator_abs::op1_range): Handle NAN.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/tree-ssa/pr107355.c: New test.
> ---
>  gcc/range-op-float.cc                    |  9 +++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/pr107355.c | 13 +++++++++++++
>  2 files changed, 22 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107355.c
>
> diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
> index 8777bc70d71..04208c88dd1 100644
> --- a/gcc/range-op-float.cc
> +++ b/gcc/range-op-float.cc
> @@ -1269,6 +1269,15 @@ foperator_abs::op1_range (frange &r, tree type,
>    positives.update_nan (/*sign=*/false);
>    positives.intersect (lhs);
>    r = positives;
> +  // Add -NAN if relevant.
> +  if (r.maybe_isnan ())
> +    {
> +      frange neg_nan;
> +      neg_nan.set_nan (type, true);
> +      r.union_ (neg_nan);
> +    }
> +  if (r.known_isnan ())
> +    return true;
>    // Then add the negative of each pair:
>    // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20].
>    r.union_ (frange (type,
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c
> new file mode 100644
> index 00000000000..40796344bfb
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c
> @@ -0,0 +1,13 @@
> +// { dg-do compile }
> +// { dg-options "-O2 -fno-guess-branch-probability -fsanitize=float-cast-overflow --param=max-jump-thread-duplication-stmts=240" }
> +
> +float f;
> +
> +void
> +foo (double d)
> +{
> +  (char) f;
> +  long l = __builtin_fabs (d);
> +  (char) f;
> +  (long) d;
> +}
> --
> 2.37.3
>


      reply	other threads:[~2022-10-24 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24 13:33 Aldy Hernandez
2022-10-24 13:34 ` Aldy Hernandez [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=CAGm3qMXX8FbLmJdDsWb2KQcZQq3S702SdCiAyNfWZHS7_1MXjw@mail.gmail.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).