public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges.
@ 2022-09-20 18:22 Aldy Hernandez
  2022-09-21  7:38 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Aldy Hernandez @ 2022-09-20 18:22 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

Undefined ranges have undefined NAN bits.  We can't depend on them,
as they may contain garbage.  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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges.
  2022-09-20 18:22 [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges Aldy Hernandez
@ 2022-09-21  7:38 ` Richard Biener
  2022-09-21  7:52   ` Aldy Hernandez
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2022-09-21  7:38 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches

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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges.
  2022-09-21  7:38 ` Richard Biener
@ 2022-09-21  7:52   ` Aldy Hernandez
  2022-09-21  9:36     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Aldy Hernandez @ 2022-09-21  7:52 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC patches

[-- 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges.
  2022-09-21  7:52   ` Aldy Hernandez
@ 2022-09-21  9:36     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-09-21  9:36 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches

On Wed, Sep 21, 2022 at 9:52 AM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> 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?

LGTM

>
> 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
> > >
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-21  9:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 18:22 [COMMITTED] frange::maybe_isnan() should return FALSE for undefined ranges Aldy Hernandez
2022-09-21  7:38 ` Richard Biener
2022-09-21  7:52   ` Aldy Hernandez
2022-09-21  9:36     ` Richard Biener

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).