[5/5] Sanitize legacy_{lower,upper}_bound

Message ID 20230228134748.07F8D13440@imap2.suse-dmz.suse.de
State New
Headers
Series Fix irange::legacy_upper_bound |

Commit Message

Richard Biener Feb. 28, 2023, 1:47 p.m. UTC
  * value-range.h (irange::legacy_lower_bound): Remove
	pair argument.
	(irange::legacy_upper_bound): Likewise.
	(irange::lower_bound): Commonize asserts, adjust.
	(irange::upper_bound): Likewise.
	* value-range.cc (irange::legacy_lower_bound): Remove
	asserts done in the caller.  Use min/max consistently.
	(irange::legacy_upper_bound): Likewise.
---
 gcc/value-range.cc | 24 ++++++++----------------
 gcc/value-range.h  | 18 ++++++++++++------
 2 files changed, 20 insertions(+), 22 deletions(-)
  

Comments

Aldy Hernandez March 1, 2023, 10:39 a.m. UTC | #1
Similar to my num_pairs comment.  If we're fixing missed optimizations, 
then yes.  Otherwise I'd prefer to remove it soon.

That being said, you are the release manager and if you feel strongly 
about this I would defer to you.

Aldy

On 2/28/23 14:47, Richard Biener via Gcc-patches wrote:
> 	* value-range.h (irange::legacy_lower_bound): Remove
> 	pair argument.
> 	(irange::legacy_upper_bound): Likewise.
> 	(irange::lower_bound): Commonize asserts, adjust.
> 	(irange::upper_bound): Likewise.
> 	* value-range.cc (irange::legacy_lower_bound): Remove
> 	asserts done in the caller.  Use min/max consistently.
> 	(irange::legacy_upper_bound): Likewise.
> ---
>   gcc/value-range.cc | 24 ++++++++----------------
>   gcc/value-range.h  | 18 ++++++++++++------
>   2 files changed, 20 insertions(+), 22 deletions(-)
> 
> diff --git a/gcc/value-range.cc b/gcc/value-range.cc
> index 143af5601c7..eaf6139a1b5 100644
> --- a/gcc/value-range.cc
> +++ b/gcc/value-range.cc
> @@ -1190,60 +1190,52 @@ irange::verify_range ()
>       }
>   }
>   
> -// Return the lower bound for a sub-range.  PAIR is the sub-range in
> -// question.
> +// Return the lower bound for a sub-range.
>   
>   wide_int
> -irange::legacy_lower_bound (unsigned pair) const
> +irange::legacy_lower_bound () const
>   {
>     gcc_checking_assert (legacy_mode_p ());
>     if (symbolic_p ())
>       {
>         value_range numeric_range (*this);
>         numeric_range.normalize_symbolics ();
> -      return numeric_range.legacy_lower_bound (pair);
> +      return numeric_range.legacy_lower_bound ();
>       }
> -  gcc_checking_assert (m_num_ranges > 0);
> -  gcc_checking_assert (pair + 1 <= num_pairs ());
>     if (m_kind == VR_ANTI_RANGE)
>       {
>         tree typ = type (), t;
> -      gcc_checking_assert (pair == 0);
>         if (vrp_val_is_min (min ()))
>   	t = wide_int_to_tree (typ, wi::to_wide (max ()) + 1);
>         else
>   	t = vrp_val_min (typ);
>         return wi::to_wide (t);
>       }
> - return wi::to_wide (tree_lower_bound (pair));
> + return wi::to_wide (min ());
>   }
>   
> -// Return the upper bound for a sub-range.  PAIR is the sub-range in
> -// question.
> +// Return the upper bound for a sub-range.
>   
>   wide_int
> -irange::legacy_upper_bound (unsigned pair) const
> +irange::legacy_upper_bound () const
>   {
>     gcc_checking_assert (legacy_mode_p ());
>     if (symbolic_p ())
>       {
>         value_range numeric_range (*this);
>         numeric_range.normalize_symbolics ();
> -      return numeric_range.legacy_upper_bound (pair);
> +      return numeric_range.legacy_upper_bound ();
>       }
> -  gcc_checking_assert (m_num_ranges > 0);
> -  gcc_checking_assert (pair + 1 <= num_pairs ());
>     if (m_kind == VR_ANTI_RANGE)
>       {
>         tree typ = type (), t;
> -      gcc_checking_assert (pair == 0);
>         if (!vrp_val_is_max (max ()))
>   	t = vrp_val_max (typ);
>         else
>   	t = wide_int_to_tree (typ, wi::to_wide (min ()) - 1);
>         return wi::to_wide (t);
>       }
> -  return wi::to_wide (tree_upper_bound (pair));
> +  return wi::to_wide (max ());
>   }
>   
>   bool
> diff --git a/gcc/value-range.h b/gcc/value-range.h
> index cfb51bad915..ed8163ed218 100644
> --- a/gcc/value-range.h
> +++ b/gcc/value-range.h
> @@ -193,8 +193,8 @@ protected:
>     void legacy_union (irange *, const irange *);
>     void legacy_intersect (irange *, const irange *);
>     void verify_range ();
> -  wide_int legacy_lower_bound (unsigned = 0) const;
> -  wide_int legacy_upper_bound (unsigned) const;
> +  wide_int legacy_lower_bound () const;
> +  wide_int legacy_upper_bound () const;
>     int value_inside_range (tree) const;
>     bool maybe_anti_range () const;
>     void copy_to_legacy (const irange &);
> @@ -918,10 +918,13 @@ irange::set_varying (tree type)
>   inline wide_int
>   irange::lower_bound (unsigned pair) const
>   {
> -  if (legacy_mode_p ())
> -    return legacy_lower_bound (pair);
>     gcc_checking_assert (m_num_ranges > 0);
>     gcc_checking_assert (pair + 1 <= num_pairs ());
> +  if (legacy_mode_p ())
> +    {
> +      gcc_checking_assert (pair == 0);
> +      return legacy_lower_bound ();
> +    }
>     return wi::to_wide (tree_lower_bound (pair));
>   }
>   
> @@ -931,10 +934,13 @@ irange::lower_bound (unsigned pair) const
>   inline wide_int
>   irange::upper_bound (unsigned pair) const
>   {
> -  if (legacy_mode_p ())
> -    return legacy_upper_bound (pair);
>     gcc_checking_assert (m_num_ranges > 0);
>     gcc_checking_assert (pair + 1 <= num_pairs ());
> +  if (legacy_mode_p ())
> +    {
> +      gcc_checking_assert (pair == 0);
> +      return legacy_upper_bound ();
> +    }
>     return wi::to_wide (tree_upper_bound (pair));
>   }
>
  

Patch

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 143af5601c7..eaf6139a1b5 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1190,60 +1190,52 @@  irange::verify_range ()
     }
 }
 
-// Return the lower bound for a sub-range.  PAIR is the sub-range in
-// question.
+// Return the lower bound for a sub-range.
 
 wide_int
-irange::legacy_lower_bound (unsigned pair) const
+irange::legacy_lower_bound () const
 {
   gcc_checking_assert (legacy_mode_p ());
   if (symbolic_p ())
     {
       value_range numeric_range (*this);
       numeric_range.normalize_symbolics ();
-      return numeric_range.legacy_lower_bound (pair);
+      return numeric_range.legacy_lower_bound ();
     }
-  gcc_checking_assert (m_num_ranges > 0);
-  gcc_checking_assert (pair + 1 <= num_pairs ());
   if (m_kind == VR_ANTI_RANGE)
     {
       tree typ = type (), t;
-      gcc_checking_assert (pair == 0);
       if (vrp_val_is_min (min ()))
 	t = wide_int_to_tree (typ, wi::to_wide (max ()) + 1);
       else
 	t = vrp_val_min (typ);
       return wi::to_wide (t);
     }
- return wi::to_wide (tree_lower_bound (pair));
+ return wi::to_wide (min ());
 }
 
-// Return the upper bound for a sub-range.  PAIR is the sub-range in
-// question.
+// Return the upper bound for a sub-range.
 
 wide_int
-irange::legacy_upper_bound (unsigned pair) const
+irange::legacy_upper_bound () const
 {
   gcc_checking_assert (legacy_mode_p ());
   if (symbolic_p ())
     {
       value_range numeric_range (*this);
       numeric_range.normalize_symbolics ();
-      return numeric_range.legacy_upper_bound (pair);
+      return numeric_range.legacy_upper_bound ();
     }
-  gcc_checking_assert (m_num_ranges > 0);
-  gcc_checking_assert (pair + 1 <= num_pairs ());
   if (m_kind == VR_ANTI_RANGE)
     {
       tree typ = type (), t;
-      gcc_checking_assert (pair == 0);
       if (!vrp_val_is_max (max ()))
 	t = vrp_val_max (typ);
       else
 	t = wide_int_to_tree (typ, wi::to_wide (min ()) - 1);
       return wi::to_wide (t);
     }
-  return wi::to_wide (tree_upper_bound (pair));
+  return wi::to_wide (max ());
 }
 
 bool
diff --git a/gcc/value-range.h b/gcc/value-range.h
index cfb51bad915..ed8163ed218 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -193,8 +193,8 @@  protected:
   void legacy_union (irange *, const irange *);
   void legacy_intersect (irange *, const irange *);
   void verify_range ();
-  wide_int legacy_lower_bound (unsigned = 0) const;
-  wide_int legacy_upper_bound (unsigned) const;
+  wide_int legacy_lower_bound () const;
+  wide_int legacy_upper_bound () const;
   int value_inside_range (tree) const;
   bool maybe_anti_range () const;
   void copy_to_legacy (const irange &);
@@ -918,10 +918,13 @@  irange::set_varying (tree type)
 inline wide_int
 irange::lower_bound (unsigned pair) const
 {
-  if (legacy_mode_p ())
-    return legacy_lower_bound (pair);
   gcc_checking_assert (m_num_ranges > 0);
   gcc_checking_assert (pair + 1 <= num_pairs ());
+  if (legacy_mode_p ())
+    {
+      gcc_checking_assert (pair == 0);
+      return legacy_lower_bound ();
+    }
   return wi::to_wide (tree_lower_bound (pair));
 }
 
@@ -931,10 +934,13 @@  irange::lower_bound (unsigned pair) const
 inline wide_int
 irange::upper_bound (unsigned pair) const
 {
-  if (legacy_mode_p ())
-    return legacy_upper_bound (pair);
   gcc_checking_assert (m_num_ranges > 0);
   gcc_checking_assert (pair + 1 <= num_pairs ());
+  if (legacy_mode_p ())
+    {
+      gcc_checking_assert (pair == 0);
+      return legacy_upper_bound ();
+    }
   return wi::to_wide (tree_upper_bound (pair));
 }