[2/5] fend off anti-ranges from value-range-storage

Message ID 20230228134725.02E8813440@imap2.suse-dmz.suse.de
State Accepted
Headers
Series Fix irange::legacy_upper_bound |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Richard Biener Feb. 28, 2023, 1:47 p.m. UTC
  The following avoids the need to special-case storage requirement
and copying for irange_storage_slot by making sure we canonicalize
such ranges to int_range<2>.

	* tree-ssanames.cc (range_info_set_range): If receiving
	an anti-range recurse with a temporary int_range<2>.
	* value-range-storage.cc (irange_storage_slot::size):
	Assert we're not asking for a VR_ANTI_RANGE.
---
 gcc/tree-ssanames.cc       | 3 +++
 gcc/value-range-storage.cc | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
  

Comments

Aldy Hernandez March 1, 2023, 10:10 a.m. UTC | #1
OK.

Thanks.

On Tue, Feb 28, 2023 at 2:48 PM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> The following avoids the need to special-case storage requirement
> and copying for irange_storage_slot by making sure we canonicalize
> such ranges to int_range<2>.
>
>         * tree-ssanames.cc (range_info_set_range): If receiving
>         an anti-range recurse with a temporary int_range<2>.
>         * value-range-storage.cc (irange_storage_slot::size):
>         Assert we're not asking for a VR_ANTI_RANGE.
> ---
>  gcc/tree-ssanames.cc       | 3 +++
>  gcc/value-range-storage.cc | 2 +-
>  2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
> index 08aa166ef17..23468958586 100644
> --- a/gcc/tree-ssanames.cc
> +++ b/gcc/tree-ssanames.cc
> @@ -127,6 +127,9 @@ range_info_get_range (tree name, vrange &r)
>  inline bool
>  range_info_set_range (tree name, const vrange &r)
>  {
> +  if (r.kind () == VR_ANTI_RANGE)
> +    return range_info_set_range (name, int_range<2> (as_a <irange> (r)));
> +
>    if (!range_info_p (name) || !range_info_fits_p (name, r))
>      {
>        if (range_info_p (name))
> diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
> index bf23f6dd476..79ab2921a03 100644
> --- a/gcc/value-range-storage.cc
> +++ b/gcc/value-range-storage.cc
> @@ -182,7 +182,7 @@ irange_storage_slot::get_irange (irange &r, tree type) const
>  size_t
>  irange_storage_slot::size (const irange &r)
>  {
> -  gcc_checking_assert (!r.undefined_p ());
> +  gcc_checking_assert (!r.undefined_p () && r.kind () != VR_ANTI_RANGE);
>
>    unsigned prec = TYPE_PRECISION (r.type ());
>    unsigned n = num_wide_ints_needed (r);
> --
> 2.35.3
>
  

Patch

diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 08aa166ef17..23468958586 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -127,6 +127,9 @@  range_info_get_range (tree name, vrange &r)
 inline bool
 range_info_set_range (tree name, const vrange &r)
 {
+  if (r.kind () == VR_ANTI_RANGE)
+    return range_info_set_range (name, int_range<2> (as_a <irange> (r)));
+
   if (!range_info_p (name) || !range_info_fits_p (name, r))
     {
       if (range_info_p (name))
diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index bf23f6dd476..79ab2921a03 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -182,7 +182,7 @@  irange_storage_slot::get_irange (irange &r, tree type) const
 size_t
 irange_storage_slot::size (const irange &r)
 {
-  gcc_checking_assert (!r.undefined_p ());
+  gcc_checking_assert (!r.undefined_p () && r.kind () != VR_ANTI_RANGE);
 
   unsigned prec = TYPE_PRECISION (r.type ());
   unsigned n = num_wide_ints_needed (r);