public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
	gcc-patches@gcc.gnu.org,  Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [PATCH] range-op-float: Fix up -ffinite-math-only range extension and don't extend into infinities [PR109008]
Date: Tue, 21 Mar 2023 13:56:36 +0100	[thread overview]
Message-ID: <CAGm3qMXU_PHpL6s+4Bb64R6mf0d-uaWyv1bMPM=gUKsN2dtzWA@mail.gmail.com> (raw)
In-Reply-To: <ZBiGXa50aRLhw+vY@tucnak>

On Mon, Mar 20, 2023 at 5:14 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Mon, Mar 13, 2023 at 09:41:47AM +0100, Aldy Hernandez wrote:
> > On 3/13/23 09:06, Jakub Jelinek wrote:
> > > On Mon, Mar 13, 2023 at 08:59:15AM +0100, Aldy Hernandez wrote:
> > > > > Yes, sure - I just noticed that we're forced to use high-level API for
> > > > > something that's quite low-level and should be internal (a range
> > > > > "breaking" internal consistency checks).
> > > >
> > > > Yeah, let's fix the API.  No sense hacking around things if what we need is
> > > > to tweak the design.
> > > >
> > > > I don't like hacking around things.  It always comes back to bite me ;-).
> > >
> > > Sure.  The current state is that I think the actual bugs are fixed except
> > > for the !MODE_HAS_INFINITIES case which people rarely use, so fixing up the
> > > API can wait even to next release.
> > >
> > > For !MODE_HAS_INFINITIES, I wonder if the best fix wouldn't be to change
> > > set and a few other spots, so that if the boundaries are
> > > real_min_representable/real_max_representable, we widen them to -inf and inf
> > > and change frange_val_min/max to also be dconstninf/dconstinf for
> > > !MODE_HAS_INFINITIES, because the min/max for that case (probably) really work as
> > > infinities.  Whenever we actually round that value to mode, it will become
> > > real_min_representable/real_max_representable again.
> > > But that can also wait a week.
> >
> > That sounds very reasonable.  It would remove special casing and would make
> > the code easier to read.  For that matter, that was what I had in the
> > original implementation.
>
> I think we don't want to remove the special casing for -ffinite-math-only
> on types which do support infinities.
> Thinking further on it, perhaps for !MODE_HAS_INFINITIES a better fix would
> be to do something like the patch below.
> Consider say having a range of VAX float type:
> #define M0 -FLT_MAX
> #define M1 nextafterf (F0, FLT_MAX)
> #define M2 nextafterf (M1, FLT_MAX)
> [M2, M2] - [M0, M1]
> Or perhaps if one or both of the operands are in such a case a min and max,
> perform real_arithmetic recurse on the argument replaced with
> dconstninf/dconstinf and then depending on inf pick the mininum or maximum
> of the two results (and carefully think about what to do if both operands
> are min/max).

LGTM.
Aldy

>
> 2023-03-20  Jakub Jelinek  <jakub@redhat.com>
>
>         * range-op-float.cc (frange_arithmetic): For !MODE_HAS_INFINITIES
>         types, pretend operands with minimum or maximum values are actually
>         infinities.
>
> --- gcc/range-op-float.cc.jj    2023-03-10 12:40:19.673108938 +0100
> +++ gcc/range-op-float.cc       2023-03-20 16:58:36.604981486 +0100
> @@ -313,8 +313,26 @@ frange_arithmetic (enum tree_code code,
>    REAL_VALUE_TYPE value;
>    enum machine_mode mode = TYPE_MODE (type);
>    bool mode_composite = MODE_COMPOSITE_P (mode);
> +  const REAL_VALUE_TYPE *pop1 = &op1;
> +  const REAL_VALUE_TYPE *pop2 = &op2;
>
> -  bool inexact = real_arithmetic (&value, code, &op1, &op2);
> +  if (!MODE_HAS_INFINITIES (mode))
> +    {
> +      // If mode doesn't have infinities, the minimum and maximum
> +      // values are saturating.  Pretend for real_arithmetic such
> +      // values are actual infinities.  real_convert will then
> +      // canonicalize the result not to be an infinity.
> +      if (frange_val_is_min (op1, type))
> +       pop1 = &dconstninf;
> +      else if (frange_val_is_max (op1, type))
> +       pop1 = &dconstinf;
> +      if (frange_val_is_min (op2, type))
> +       pop2 = &dconstninf;
> +      else if (frange_val_is_max (op2, type))
> +       pop2 = &dconstinf;
> +    }
> +
> +  bool inexact = real_arithmetic (&value, code, pop1, pop2);
>    real_convert (&result, mode, &value);
>
>    // Be extra careful if there may be discrepancies between the
>
>
>         Jakub
>


  reply	other threads:[~2023-03-21 12:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10  8:07 Jakub Jelinek
2023-03-10  8:53 ` Richard Biener
2023-03-10 10:29   ` Jakub Jelinek
2023-03-13  7:18     ` Aldy Hernandez
2023-03-13  7:50       ` Richard Biener
2023-03-13  7:59         ` Aldy Hernandez
2023-03-13  8:06           ` Jakub Jelinek
2023-03-13  8:41             ` Aldy Hernandez
2023-03-20 16:14               ` Jakub Jelinek
2023-03-21 12:56                 ` Aldy Hernandez [this message]
2023-03-21 13:28   ` Aldy Hernandez
2023-03-21 13:39     ` Jakub Jelinek
2023-03-21 13:49       ` Aldy Hernandez
2023-03-21 13:56         ` Jakub Jelinek
2023-03-22  6:32           ` Aldy Hernandez
2023-03-22  8:35             ` Jakub Jelinek
2023-03-28  7:54             ` [PATCH] range-op-float: Use get_nan_state in float_widen_lhs_range Jakub Jelinek
2023-03-28  8:50               ` Aldy Hernandez
2023-03-29  9:39                 ` Aldy Hernandez

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='CAGm3qMXU_PHpL6s+4Bb64R6mf0d-uaWyv1bMPM=gUKsN2dtzWA@mail.gmail.com' \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=rguenther@suse.de \
    /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).