public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-3256] Allow copying of symbolic ranges to an irange.
@ 2020-09-17 10:52 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2020-09-17 10:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:80cbca32464ae05931c0ae425eec7d1f373946eb

commit r11-3256-g80cbca32464ae05931c0ae425eec7d1f373946eb
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Sep 15 17:33:48 2020 +0200

    Allow copying of symbolic ranges to an irange.
    
    This fixes an ICE when trying to copy a legacy value_range containing
    a symbolic to a multi-range:
    
            min = make_ssa_name (type);
            max = build_int_cst (type, 55);
            value_range vv (min, max);
            int_range<2> vr = vv;
    
    gcc/ChangeLog:
    
            * range-op.cc (multi_precision_range_tests): Normalize symbolics when copying to a
            multi-range.
            * value-range.cc (irange::copy_legacy_range): Add test.

Diff:
---
 gcc/range-op.cc    | 15 +++++++++++++++
 gcc/value-range.cc | 19 +++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index fbf78be0a3c..3ab268f101e 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3453,6 +3453,21 @@ multi_precision_range_tests ()
   small = big;
   ASSERT_TRUE (small == int_range<1> (INT (21), INT (21), VR_ANTI_RANGE));
 
+  // Copying a legacy symbolic to an int_range should normalize the
+  // symbolic at copy time.
+  {
+    tree ssa = make_ssa_name (integer_type_node);
+    value_range legacy_range (ssa, INT (25));
+    int_range<2> copy = legacy_range;
+    ASSERT_TRUE (copy == int_range<2>  (vrp_val_min (integer_type_node),
+					INT (25)));
+
+    // Test that copying ~[abc_23, abc_23] to a multi-range yields varying.
+    legacy_range = value_range (ssa, ssa, VR_ANTI_RANGE);
+    copy = legacy_range;
+    ASSERT_TRUE (copy.varying_p ());
+  }
+
   range3_tests ();
 }
 
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 20aa4f114c9..ed2c322ded9 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -92,7 +92,12 @@ irange::copy_legacy_range (const irange &src)
   else if (src.varying_p ())
     set_varying (src.type ());
   else if (src.kind () == VR_ANTI_RANGE)
-    set (src.min (), src.max (), VR_ANTI_RANGE);
+    {
+      if (src.legacy_mode_p () && !range_has_numeric_bounds_p (&src))
+	set_varying (src.type ());
+      else
+	set (src.min (), src.max (), VR_ANTI_RANGE);
+    }
   else if (legacy_mode_p () && src.maybe_anti_range ())
     {
       int_range<3> tmp (src);
@@ -101,7 +106,17 @@ irange::copy_legacy_range (const irange &src)
 	   VR_ANTI_RANGE);
     }
   else
-    set (src.min (), src.max (), VR_RANGE);
+    {
+      // If copying legacy to int_range, normalize any symbolics.
+      if (src.legacy_mode_p () && !range_has_numeric_bounds_p (&src))
+	{
+	  value_range cst (src);
+	  cst.normalize_symbolics ();
+	  set (cst.min (), cst.max ());
+	  return;
+	}
+      set (src.min (), src.max ());
+    }
 }
 
 // Swap min/max if they are out of order.  Return TRUE if further


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-17 10:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 10:52 [gcc r11-3256] Allow copying of symbolic ranges to an irange 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).