public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Decimal floats can never be an frange::singleton_p.
@ 2022-09-05 13:47 Aldy Hernandez
  2022-09-05 13:51 ` Jakub Jelinek
  2022-09-05 15:55 ` Aldy Hernandez
  0 siblings, 2 replies; 3+ messages in thread
From: Aldy Hernandez @ 2022-09-05 13:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Jakub Jelinek, Andrew MacLeod, Aldy Hernandez

As Jakub mentioned in the PR, because many numbers have multiple
possible representations, we can't reliably return true here.

I'll commit this if tests pass.

I wonder if its worth even handling decimal floats in frange, since
there's a lot of things we can't represent.  I suppose even though we
could never propagate an actual value with VRP, we could fold
conditionals (symbolic and stuff outside ranges, etc) ??.  

Thoughts?

	PR middle-end/106831

gcc/ChangeLog:

	* value-range.cc (frange::singleton_p): Return false for
	DECIMAL_FLOAT_TYPE_P.
---
 gcc/value-range.cc | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index c3f668a811a..12a3750d078 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -647,6 +647,14 @@ frange::singleton_p (tree *result) const
       if (HONOR_NANS (m_type) && !get_nan ().no_p ())
 	return false;
 
+      // Because the significand is not normalized (there is no
+      // implicit leading "1").  Most values with less than 7
+      // significant digits have multiple possible representations.
+      // Zero has 192 possible representations (or twice that for
+      // signed zeros).
+      if (DECIMAL_FLOAT_TYPE_P (m_type))
+	return false;
+
       // Return the appropriate zero if known.
       if (HONOR_SIGNED_ZEROS (m_type) && zero_p ())
 	{
-- 
2.37.1


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

* Re: [PATCH] Decimal floats can never be an frange::singleton_p.
  2022-09-05 13:47 [PATCH] Decimal floats can never be an frange::singleton_p Aldy Hernandez
@ 2022-09-05 13:51 ` Jakub Jelinek
  2022-09-05 15:55 ` Aldy Hernandez
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2022-09-05 13:51 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: GCC patches, Andrew MacLeod

On Mon, Sep 05, 2022 at 03:47:01PM +0200, Aldy Hernandez wrote:
> As Jakub mentioned in the PR, because many numbers have multiple
> possible representations, we can't reliably return true here.
> 
> I'll commit this if tests pass.
> 
> I wonder if its worth even handling decimal floats in frange, since
> there's a lot of things we can't represent.  I suppose even though we
> could never propagate an actual value with VRP, we could fold
> conditionals (symbolic and stuff outside ranges, etc) ??.  
> 
> Thoughts?
> 
> 	PR middle-end/106831
> 
> gcc/ChangeLog:
> 
> 	* value-range.cc (frange::singleton_p): Return false for
> 	DECIMAL_FLOAT_TYPE_P.
> ---
>  gcc/value-range.cc | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/gcc/value-range.cc b/gcc/value-range.cc
> index c3f668a811a..12a3750d078 100644
> --- a/gcc/value-range.cc
> +++ b/gcc/value-range.cc
> @@ -647,6 +647,14 @@ frange::singleton_p (tree *result) const
>        if (HONOR_NANS (m_type) && !get_nan ().no_p ())
>  	return false;
>  
> +      // Because the significand is not normalized (there is no
> +      // implicit leading "1").  Most values with less than 7
> +      // significant digits have multiple possible representations.
> +      // Zero has 192 possible representations (or twice that for
> +      // signed zeros).

The exact details (7, 192) are dependent on the format, for
decimal64 it is (16, 768) and for decimal128 (34, 12288).

	Jakub


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

* Re: [PATCH] Decimal floats can never be an frange::singleton_p.
  2022-09-05 13:47 [PATCH] Decimal floats can never be an frange::singleton_p Aldy Hernandez
  2022-09-05 13:51 ` Jakub Jelinek
@ 2022-09-05 15:55 ` Aldy Hernandez
  1 sibling, 0 replies; 3+ messages in thread
From: Aldy Hernandez @ 2022-09-05 15:55 UTC (permalink / raw)
  To: GCC patches; +Cc: Jakub Jelinek, Andrew MacLeod

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

Final version of the patch.  Disable frange for DECIMAL_FLOAT_MODE_P altogether.

Tested on x86-64 Linux with regstrap as well as mpfr tests.

On Mon, Sep 5, 2022 at 3:47 PM Aldy Hernandez <aldyh@redhat.com> wrote:
>
> As Jakub mentioned in the PR, because many numbers have multiple
> possible representations, we can't reliably return true here.
>
> I'll commit this if tests pass.
>
> I wonder if its worth even handling decimal floats in frange, since
> there's a lot of things we can't represent.  I suppose even though we
> could never propagate an actual value with VRP, we could fold
> conditionals (symbolic and stuff outside ranges, etc) ??.
>
> Thoughts?
>
>         PR middle-end/106831
>
> gcc/ChangeLog:
>
>         * value-range.cc (frange::singleton_p): Return false for
>         DECIMAL_FLOAT_TYPE_P.
> ---
>  gcc/value-range.cc | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/gcc/value-range.cc b/gcc/value-range.cc
> index c3f668a811a..12a3750d078 100644
> --- a/gcc/value-range.cc
> +++ b/gcc/value-range.cc
> @@ -647,6 +647,14 @@ frange::singleton_p (tree *result) const
>        if (HONOR_NANS (m_type) && !get_nan ().no_p ())
>         return false;
>
> +      // Because the significand is not normalized (there is no
> +      // implicit leading "1").  Most values with less than 7
> +      // significant digits have multiple possible representations.
> +      // Zero has 192 possible representations (or twice that for
> +      // signed zeros).
> +      if (DECIMAL_FLOAT_TYPE_P (m_type))
> +       return false;
> +
>        // Return the appropriate zero if known.
>        if (HONOR_SIGNED_ZEROS (m_type) && zero_p ())
>         {
> --
> 2.37.1
>

[-- Attachment #2: 0002-Disable-decimal-floating-point-in-frange.patch --]
[-- Type: text/x-patch, Size: 2458 bytes --]

From 4f32e08f7317c52ed72ee48447cb4dd5d68a5c28 Mon Sep 17 00:00:00 2001
From: Aldy Hernandez <aldyh@redhat.com>
Date: Mon, 5 Sep 2022 15:41:39 +0200
Subject: [PATCH] Disable decimal floating point in frange.

As Jakub mentioned in the PR, because many numbers have multiple
possible representations, we can't reliably return true for singleton_p.
For that matter, we may not be capable of modeling them just yet.
Disabling them until someone with DFP knowledge can opine or extend
frange.

	PR middle-end/106831

gcc/ChangeLog:

	* value-range.h (frange::supports_p): Disable decimal floats.
	* range-op-float.cc (frange_drop_inf): Remove DECIMAL_FLOAT_MODE_P
	check.
	(frange_drop_ninf): Same.
---
 gcc/range-op-float.cc | 10 ----------
 gcc/value-range.h     |  5 ++++-
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 7301e5a060b..050f07a9867 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -204,11 +204,6 @@ frelop_early_resolve (irange &r, tree type,
 static inline void
 frange_drop_inf (frange &r, tree type)
 {
-  // FIXME: build_real() bails on decimal float modes when called with
-  // a max representable endpoint.
-  if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
-    return;
-
   REAL_VALUE_TYPE max;
   real_max_representable (&max, type);
   frange tmp (type, r.lower_bound (), max);
@@ -221,11 +216,6 @@ frange_drop_inf (frange &r, tree type)
 static inline void
 frange_drop_ninf (frange &r, tree type)
 {
-  // FIXME: build_real() bails on decimal float modes when called with
-  // a max representable endpoint.
-  if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
-    return;
-
   REAL_VALUE_TYPE min;
   real_min_representable (&min, type);
   frange tmp (type, min, r.upper_bound ());
diff --git a/gcc/value-range.h b/gcc/value-range.h
index bc00f3d5b08..645dc76c33a 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -338,7 +338,10 @@ public:
 	  value_range_kind = VR_RANGE);
   static bool supports_p (const_tree type)
   {
-    return SCALAR_FLOAT_TYPE_P (type);
+    // ?? Decimal floats can have multiple representations for the
+    // same number.  Supporting them may be as simple as just
+    // disabling them in singleton_p.  No clue.
+    return SCALAR_FLOAT_TYPE_P (type) && !DECIMAL_FLOAT_TYPE_P (type);
   }
   virtual tree type () const override;
   virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
-- 
2.37.1


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

end of thread, other threads:[~2022-09-05 15:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 13:47 [PATCH] Decimal floats can never be an frange::singleton_p Aldy Hernandez
2022-09-05 13:51 ` Jakub Jelinek
2022-09-05 15:55 ` Aldy Hernandez

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