public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC patches <gcc-patches@gcc.gnu.org>
Subject: Re: [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges.
Date: Wed, 21 Sep 2022 09:52:04 +0200	[thread overview]
Message-ID: <CAGm3qMXzDhdPkipeuUHQDSj7xC41Rd0E3gzp9nS0embghv0fkw@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc1DMo3Ge6VHbS0WioXS5owG-=hCwLJegtdUbFHvFsSh9w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1314 bytes --]

The reason the flags were uninitialized was because they were unused,
similarly for m_type.  But you're right, it is icky and prone to bugs.
I just thought it was cheap to set_undefined by just flipping
m_kind=VR_UNDEFINED, but it smells like premature optimization.

How about this?

Aldy

On Wed, Sep 21, 2022 at 9:39 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Tue, Sep 20, 2022 at 8:23 PM Aldy Hernandez via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > Undefined ranges have undefined NAN bits.  We can't depend on them,
> > as they may contain garbage.
>
> Ick ;)  Can you add a comment at least?
>
> > This patch returns false from
> > maybe_isnan() for undefined ranges (the empty set).
> >
> > gcc/ChangeLog:
> >
> >         * value-range.h (frange::maybe_isnan): Return false for
> >         undefined ranges.
> > ---
> >  gcc/value-range.h | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/gcc/value-range.h b/gcc/value-range.h
> > index 7d5584a9294..325ed08f290 100644
> > --- a/gcc/value-range.h
> > +++ b/gcc/value-range.h
> > @@ -1210,6 +1210,8 @@ frange::known_isinf () const
> >  inline bool
> >  frange::maybe_isnan () const
> >  {
> > +  if (undefined_p ())
> > +    return false;
> >    return m_pos_nan || m_neg_nan;
> >  }
> >
> > --
> > 2.37.1
> >
>

[-- Attachment #2: 0002-Clear-unused-flags-in-frange-for-undefined-ranges.patch --]
[-- Type: text/x-patch, Size: 2074 bytes --]

From f96eb8f4386f2cec67dbf20ab3650aa756fe218a Mon Sep 17 00:00:00 2001
From: Aldy Hernandez <aldyh@redhat.com>
Date: Wed, 21 Sep 2022 09:49:14 +0200
Subject: [PATCH] Clear unused flags in frange for undefined ranges.

gcc/ChangeLog:

	* value-range.cc (frange::combine_zeros): Call set_undefined.
	(frange::intersect_nans): Same.
	(frange::intersect): Same.
	(frange::verify_range): Undefined ranges do not have a type.
	* value-range.h (frange::set_undefined): Clear NAN flags and type.
---
 gcc/value-range.cc | 8 ++++----
 gcc/value-range.h  | 4 ++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index dc42b6d3120..505eb9211a7 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -422,7 +422,7 @@ frange::combine_zeros (const frange &r, bool union_p)
       if (maybe_isnan ())
 	m_kind = VR_NAN;
       else
-	m_kind = VR_UNDEFINED;
+	set_undefined ();
       changed = true;
     }
   return changed;
@@ -506,7 +506,7 @@ frange::intersect_nans (const frange &r)
   if (maybe_isnan ())
     m_kind = VR_NAN;
   else
-    m_kind = VR_UNDEFINED;
+    set_undefined ();
   if (flag_checking)
     verify_range ();
   return true;
@@ -558,7 +558,7 @@ frange::intersect (const vrange &v)
       if (maybe_isnan ())
 	m_kind = VR_NAN;
       else
-	m_kind = VR_UNDEFINED;
+	set_undefined ();
       if (flag_checking)
 	verify_range ();
       return true;
@@ -696,7 +696,7 @@ frange::verify_range ()
   switch (m_kind)
     {
     case VR_UNDEFINED:
-      // m_type is ignored.
+      gcc_checking_assert (!m_type);
       return;
     case VR_VARYING:
       gcc_checking_assert (m_type);
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 325ed08f290..3668b331187 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -1083,6 +1083,10 @@ inline void
 frange::set_undefined ()
 {
   m_kind = VR_UNDEFINED;
+  m_type = NULL;
+  m_pos_nan = false;
+  m_neg_nan = false;
+  // m_min and m_min are unitialized as they are REAL_VALUE_TYPE ??.
   if (flag_checking)
     verify_range ();
 }
-- 
2.37.1


  reply	other threads:[~2022-09-21  7:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 18:22 Aldy Hernandez
2022-09-21  7:38 ` Richard Biener
2022-09-21  7:52   ` Aldy Hernandez [this message]
2022-09-21  9:36     ` Richard Biener

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=CAGm3qMXzDhdPkipeuUHQDSj7xC41Rd0E3gzp9nS0embghv0fkw@mail.gmail.com \
    --to=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.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).