From: Aldy Hernandez <aldyh@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: GCC patches <gcc-patches@gcc.gnu.org>,
Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [PATCH] [ranger] x == -0.0 does not mean we can replace x with -0.0
Date: Mon, 29 Aug 2022 15:13:21 +0200 [thread overview]
Message-ID: <CAGm3qMVKAob=mhkqKfB4nj9m0pupCRK6zw1xkkvCF4QRm7U+sQ@mail.gmail.com> (raw)
In-Reply-To: <Ywj3dRF7EaiXhEPm@tucnak>
On Fri, Aug 26, 2022 at 6:40 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Fri, Aug 26, 2022 at 05:46:06PM +0200, Aldy Hernandez wrote:
> > On the true side of x == -0.0, we can't just blindly value propagate
> > the -0.0 into every use of x because x could be +0.0 (or vice versa).
> >
> > With this change, we only allow the transformation if
> > !HONOR_SIGNED_ZEROS or if the range is known not to contain 0.
> >
> > Will commit after tests complete.
> >
> > gcc/ChangeLog:
> >
> > * range-op-float.cc (foperator_equal::op1_range): Do not blindly
> > copy op2 range when honoring signed zeros.
> > ---
> > gcc/range-op-float.cc | 17 +++++++++++++++--
> > 1 file changed, 15 insertions(+), 2 deletions(-)
> >
> > diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
> > index ad2fae578d2..ff9fe312acf 100644
> > --- a/gcc/range-op-float.cc
> > +++ b/gcc/range-op-float.cc
> > @@ -252,8 +252,21 @@ foperator_equal::op1_range (frange &r, tree type,
> > switch (get_bool_state (r, lhs, type))
> > {
> > case BRS_TRUE:
> > - // If it's true, the result is the same as OP2.
> > - r = op2;
> > + if (HONOR_SIGNED_ZEROS (type)
> > + && op2.contains_p (build_zero_cst (type)))
>
> What exactly does op2.contains_p for zero?
> Does it use real_compare/real_equal under the hood, so it is
> equivalent to op2 == 0.0 or op2 == -0.0, where both will be
> true whether op2 is -0.0 or 0.0? Or is it more strict and
> checks whether it is actually a positive zero?
frange::contains_p() uses real_compare(), so both -0.0 and 0.0 will
come out as true:
return (real_compare (GE_EXPR, TREE_REAL_CST_PTR (cst), &m_min)
&& real_compare (LE_EXPR, TREE_REAL_CST_PTR (cst), &m_max));
I thought about this some more, and you're right, dropping to VARYING
is a big hammer.
It seems to me we can do this optimization regardless, but then treat
positive and negative zero the same throughout the frange class.
Particularly, in frange::singleton_p(). We should never return TRUE
for any version of 0.0. This will keep VRP from propagating an
incorrect 0.0, since all VRP does is propagate when a range is
provably a singleton. Also, frange::zero_p() shall return true for
any version of 0.0.
I fleshed out all the relational operators (with endpoints) with this
approach, and everything worked out...including go, ada, and fortran,
which had given me headaches. As a bonus, we can get rid of the
INF/NINF property bits I was keeping around, since now the range will
have actual endpoints. I will repost the full frange endpoints patch
(and CC you) in the appropriate thread.
Aldy
> In any case, for HONOR_SIGNED_ZEROS, VARYING is unnecessary, all you
> can do is extend the r range to contain both -0.0 and +0.0 if it contains
> at least one of them.
>
> > + {
> > + // With signed zeros, x == -0.0 does not mean we can replace
> > + // x with -0.0, because x may be either +0.0 or -0.0.
> > + r.set_varying (type);
> > + }
> > + else
> > + {
> > + // If it's true, the result is the same as OP2.
> > + //
> > + // If the range does not actually contain zeros, this should
> > + // always be OK.
> > + r = op2;
> > + }
>
> !HONOR_SIGNED_ZEROS doesn't imply that negative zeros won't appear,
> but says that user doesn't care if he gets a positive or negative zero
> (unless !MODE_HAS_SIGNED_ZEROS - in that case -0.0 doesn't exist
> and one doesn't need to bother with it).
>
> Now, if all the code setting franges makes sure that for
> MODE_HAS_SIGNED_ZEROS && !HONOR_SIGNED_ZEROS if +0.0 or -0.0 are inside
> of a range, then both -0.0 and +0.0 are in the range, then yes,
> you can use r = op2;
>
> > // The TRUE side of op1 == op2 implies op1 is !NAN.
> > r.set_nan (fp_prop::NO);
> > break;
>
> Jakub
>
next prev parent reply other threads:[~2022-08-29 13:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 15:46 Aldy Hernandez
2022-08-26 16:40 ` Jakub Jelinek
2022-08-29 13:13 ` Aldy Hernandez [this message]
2022-08-29 13:21 ` Jakub Jelinek
2022-08-29 13:31 ` Aldy Hernandez
2022-08-29 14:20 ` Jeff Law
2022-08-29 14:26 ` Aldy Hernandez
2022-08-29 15:08 ` Jeff Law
2022-08-29 15:13 ` Toon Moene
2022-08-29 17:07 ` Jeff Law
2022-08-29 17:37 ` Koning, Paul
2022-08-29 19:04 ` Toon Moene
2022-08-29 15:29 ` Aldy Hernandez
2022-08-31 10:08 ` 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='CAGm3qMVKAob=mhkqKfB4nj9m0pupCRK6zw1xkkvCF4QRm7U+sQ@mail.gmail.com' \
--to=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.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).