public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Fix swapping of ranges.
@ 2023-04-26 11:47 Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Replace ad-hoc value_range dumpers with irange::dump Aldy Hernandez
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

The legacy range code has logic to swap out of order endpoints in the
irange constructor.  The new irange code expects the caller to fix any
inconsistencies, thus speeding up the common case.  However, this means
that when we remove legacy, any stragglers must be fixed.  This patch
fixes the 3 culprits found during the conversion.

gcc/ChangeLog:

	* range-op.cc (operator_cast::op1_range): Use
	create_possibly_reversed_range.
	(operator_bitwise_and::simple_op1_range_solver): Same.
	* value-range.cc (swap_out_of_order_endpoints): Delete.
	(irange::set): Remove call to swap_out_of_order_endpoints.
---
 gcc/range-op.cc    | 10 ++++++----
 gcc/value-range.cc | 47 ----------------------------------------------
 2 files changed, 6 insertions(+), 51 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index f90e78dcfbc..e47edcf3d74 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2876,8 +2876,9 @@ operator_cast::op1_range (irange &r, tree type,
 	  // Start by building the positive signed outer range for the type.
 	  wide_int lim = wi::set_bit_in_zero (TYPE_PRECISION (lhs_type),
 					      TYPE_PRECISION (type));
-	  r = int_range<1> (type, lim, wi::max_value (TYPE_PRECISION (type),
-						      SIGNED));
+	  create_possibly_reversed_range (r, type, lim,
+					  wi::max_value (TYPE_PRECISION (type),
+							 SIGNED));
 	  // For the signed part, we need to simply union the 2 ranges now.
 	  r.union_ (converted_lhs);
 
@@ -3367,7 +3368,7 @@ operator_bitwise_and::simple_op1_range_solver (irange &r, tree type,
   if (we_know_nothing)
     r.set_varying (type);
   else
-    r = int_range<1> (type, minv, maxv);
+    create_possibly_reversed_range (r, type, minv, maxv);
 
   // Solve [-INF, lhs.upper_bound ()] = x & MASK.
   //
@@ -3398,7 +3399,8 @@ operator_bitwise_and::simple_op1_range_solver (irange &r, tree type,
     }
   maxv |= ~cst2v;
   minv = sgnbit;
-  int_range<1> upper_bits (type, minv, maxv);
+  int_range<2> upper_bits;
+  create_possibly_reversed_range (upper_bits, type, minv, maxv);
   r.intersect (upper_bits);
 }
 
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index a50d1a63968..da9098139ad 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1014,46 +1014,6 @@ irange::copy_to_legacy (const irange &src)
     set (src.tree_lower_bound (), src.tree_upper_bound ());
 }
 
-// Swap MIN/MAX if they are out of order and adjust KIND appropriately.
-
-static void
-swap_out_of_order_endpoints (tree &min, tree &max, value_range_kind &kind)
-{
-  gcc_checking_assert (kind != VR_UNDEFINED);
-  if (kind == VR_VARYING)
-    return;
-  /* Wrong order for min and max, to swap them and the VR type we need
-     to adjust them.  */
-  if (tree_int_cst_lt (max, min))
-    {
-      tree one, tmp;
-
-      /* For one bit precision if max < min, then the swapped
-	 range covers all values, so for VR_RANGE it is varying and
-	 for VR_ANTI_RANGE empty range, so drop to varying as well.  */
-      if (TYPE_PRECISION (TREE_TYPE (min)) == 1)
-	{
-	  kind = VR_VARYING;
-	  return;
-	}
-
-      one = build_int_cst (TREE_TYPE (min), 1);
-      tmp = int_const_binop (PLUS_EXPR, max, one);
-      max = int_const_binop (MINUS_EXPR, min, one);
-      min = tmp;
-
-      /* There's one corner case, if we had [C+1, C] before we now have
-	 that again.  But this represents an empty value range, so drop
-	 to varying in this case.  */
-      if (tree_int_cst_lt (max, min))
-	{
-	  kind = VR_VARYING;
-	  return;
-	}
-      kind = kind == VR_RANGE ? VR_ANTI_RANGE : VR_RANGE;
-    }
-}
-
 void
 irange::irange_set (tree min, tree max)
 {
@@ -1192,13 +1152,6 @@ irange::set (tree min, tree max, value_range_kind kind)
   gcc_checking_assert (TREE_CODE (min) == INTEGER_CST
 		       && TREE_CODE (max) == INTEGER_CST);
 
-  swap_out_of_order_endpoints (min, max, kind);
-  if (kind == VR_VARYING)
-    {
-      set_varying (TREE_TYPE (min));
-      return;
-    }
-
   // Anti-ranges that can be represented as ranges should be so.
   if (kind == VR_ANTI_RANGE)
     {
-- 
2.40.0


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

* [COMMITTED] Replace ad-hoc value_range dumpers with irange::dump.
  2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
@ 2023-04-26 11:47 ` Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Remove some uses of deprecated irange API Aldy Hernandez
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

This causes a regression in gcc.c-torture/unsorted/dump-noaddr.c.

The test is asserting that two dumps are identical, but they are not
because irange dumps the type which varies between runs:

               <          VR  [irange] void (*<T3dc>) (int) [1, +INF]
               >          VR  [irange] void (*<T3da>) (int) [1, +INF]

I have changed the pretty printer for irange types to pass TDF_NOUID,
thus avoiding this problem.

gcc/ChangeLog:

	* ipa-prop.cc (ipa_print_node_jump_functions_for_edge): Use
	vrange::dump instead of ad-hoc dumper.
	* tree-ssa-strlen.cc (dump_strlen_info): Same.
	* value-range-pretty-print.cc (visit): Pass TDF_NOUID to
	dump_generic_node.
---
 gcc/ipa-prop.cc                 |  9 ++------
 gcc/tree-ssa-strlen.cc          | 40 +++++----------------------------
 gcc/value-range-pretty-print.cc |  2 +-
 3 files changed, 9 insertions(+), 42 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 1a8ff7ebb95..c6d4585aed1 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -437,13 +437,8 @@ ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
 
       if (jump_func->m_vr)
 	{
-	  fprintf (f, "         VR  ");
-	  fprintf (f, "%s[",
-		   (jump_func->m_vr->kind () == VR_ANTI_RANGE) ? "~" : "");
-	  print_decs (wi::to_wide (jump_func->m_vr->min ()), f);
-	  fprintf (f, ", ");
-	  print_decs (wi::to_wide (jump_func->m_vr->max ()), f);
-	  fprintf (f, "]\n");
+	  jump_func->m_vr->dump (f);
+	  fprintf (f, "\n");
 	}
       else
 	fprintf (f, "         Unknown VR\n");
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index 1d79034594b..dcc9e9e14ab 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -981,42 +981,14 @@ dump_strlen_info (FILE *fp, gimple *stmt, range_query *rvals)
 		  print_generic_expr (fp, si->nonzero_chars);
 		  if (TREE_CODE (si->nonzero_chars) == SSA_NAME)
 		    {
-		      value_range_kind rng = VR_UNDEFINED;
-		      wide_int min, max;
+		      value_range vr;
 		      if (rvals)
-			{
-			  value_range vr;
-			  rvals->range_of_expr (vr, si->nonzero_chars,
-						si->stmt);
-			  rng = vr.kind ();
-			  if (range_int_cst_p (&vr))
-			    {
-			      min = wi::to_wide (vr.min ());
-			      max = wi::to_wide (vr.max ());
-			    }
-			  else
-			    rng = VR_UNDEFINED;
-			}
+			rvals->range_of_expr (vr, si->nonzero_chars,
+					      si->stmt);
 		      else
-			{
-			  value_range vr;
-			  get_range_query (cfun)
-			    ->range_of_expr (vr, si->nonzero_chars);
-			  rng = vr.kind ();
-			  if (!vr.undefined_p ())
-			    {
-			      min = wi::to_wide (vr.min ());
-			      max = wi::to_wide (vr.max ());
-			    }
-			}
-
-		      if (rng == VR_RANGE || rng == VR_ANTI_RANGE)
-			{
-			  fprintf (fp, " %s[%llu, %llu]",
-				   rng == VR_RANGE ? "" : "~",
-				   (long long) min.to_uhwi (),
-				   (long long) max.to_uhwi ());
-			}
+			get_range_query (cfun)->range_of_expr (vr,
+							si->nonzero_chars);
+		      vr.dump (fp);
 		    }
 		}
 
diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc
index a11c5a621f8..8d47d8087e8 100644
--- a/gcc/value-range-pretty-print.cc
+++ b/gcc/value-range-pretty-print.cc
@@ -56,7 +56,7 @@ vrange_printer::visit (const irange &r) const
       pp_string (pp, "UNDEFINED");
       return;
     }
-  dump_generic_node (pp, r.type (), 0, TDF_NONE, false);
+  dump_generic_node (pp, r.type (), 0, TDF_NONE | TDF_NOUID, false);
   pp_character (pp, ' ');
   if (r.varying_p ())
     {
-- 
2.40.0


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

* [COMMITTED] Remove some uses of deprecated irange API.
  2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Replace ad-hoc value_range dumpers with irange::dump Aldy Hernandez
@ 2023-04-26 11:47 ` Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Convert compare_nonzero_chars to wide_ints Aldy Hernandez
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* builtins.cc (expand_builtin_strnlen): Rewrite deprecated irange
	API uses to new API.
	* gimple-predicate-analysis.cc (find_var_cmp_const): Same.
	* internal-fn.cc (get_min_precision): Same.
	* match.pd: Same.
	* tree-affine.cc (expr_to_aff_combination): Same.
	* tree-data-ref.cc (dr_step_indicator): Same.
	* tree-dfa.cc (get_ref_base_and_extent): Same.
	* tree-scalar-evolution.cc (iv_can_overflow_p): Same.
	* tree-ssa-phiopt.cc (two_value_replacement): Same.
	* tree-ssa-pre.cc (insert_into_preds_of_block): Same.
	* tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Same.
	* tree-ssa-strlen.cc (compare_nonzero_chars): Same.
	* tree-switch-conversion.cc (bit_test_cluster::emit): Same.
	* tree-vect-patterns.cc (vect_recog_divmod_pattern): Same.
	* tree.cc (get_range_pos_neg): Same.
---
 gcc/builtins.cc                  |  2 +-
 gcc/gimple-predicate-analysis.cc |  3 ++-
 gcc/internal-fn.cc               |  3 ++-
 gcc/match.pd                     | 10 +++++-----
 gcc/tree-affine.cc               |  3 ++-
 gcc/tree-data-ref.cc             |  2 +-
 gcc/tree-dfa.cc                  |  3 ++-
 gcc/tree-scalar-evolution.cc     |  6 ++++--
 gcc/tree-ssa-phiopt.cc           | 17 ++++-------------
 gcc/tree-ssa-pre.cc              |  3 ++-
 gcc/tree-ssa-reassoc.cc          |  3 ++-
 gcc/tree-ssa-strlen.cc           | 13 +++++++------
 gcc/tree-switch-conversion.cc    |  3 ++-
 gcc/tree-vect-patterns.cc        |  2 +-
 gcc/tree.cc                      |  3 ++-
 15 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index bb931242c9c..878596c240a 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -3494,7 +3494,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
   wide_int min, max;
   value_range r;
   get_global_range_query ()->range_of_expr (r, bound);
-  if (r.kind () != VR_RANGE)
+  if (r.varying_p () || r.undefined_p ())
     return NULL_RTX;
   min = r.lower_bound ();
   max = r.upper_bound ();
diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc
index c89a5b1653a..7f20f81ad86 100644
--- a/gcc/gimple-predicate-analysis.cc
+++ b/gcc/gimple-predicate-analysis.cc
@@ -307,7 +307,8 @@ find_var_cmp_const (pred_chain_union preds, gphi *phi, gimple **flag_def,
 	  value_range r;
 	  if (!INTEGRAL_TYPE_P (type)
 	      || !get_range_query (cfun)->range_of_expr (r, cond_rhs)
-	      || r.kind () != VR_RANGE)
+	      || r.undefined_p ()
+	      || r.varying_p ())
 	    continue;
 
 	  wide_int min = r.lower_bound ();
diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc
index 6e81dc05e0e..5c9da73ea11 100644
--- a/gcc/internal-fn.cc
+++ b/gcc/internal-fn.cc
@@ -775,7 +775,8 @@ get_min_precision (tree arg, signop sign)
     return prec + (orig_sign != sign);
   value_range r;
   while (!get_global_range_query ()->range_of_expr (r, arg)
-	 || r.kind () != VR_RANGE)
+	 || r.varying_p ()
+	 || r.undefined_p ())
     {
       gimple *g = SSA_NAME_DEF_STMT (arg);
       if (is_gimple_assign (g)
diff --git a/gcc/match.pd b/gcc/match.pd
index e89ba57e30b..34e1a5c1b46 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -525,7 +525,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       value_range vr0;
       if (ovf1 == wi::OVF_NONE && ovf2 == wi::OVF_NONE
 	  && get_global_range_query ()->range_of_expr (vr0, @4)
-	  && vr0.kind () == VR_RANGE)
+	  && !vr0.varying_p () && !vr0.undefined_p ())
 	{
 	  wide_int wmin0 = vr0.lower_bound ();
 	  wide_int wmax0 = vr0.upper_bound ();
@@ -566,7 +566,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       value_range vr0;
       if (ovf1 == wi::OVF_NONE && ovf2 == wi::OVF_NONE
 	  && get_global_range_query ()->range_of_expr (vr0, @0)
-	  && vr0.kind () == VR_RANGE)
+	  && !vr0.varying_p () && !vr0.undefined_p ())
 	{
 	  wide_int wmin0 = vr0.lower_bound ();
 	  wide_int wmax0 = vr0.upper_bound ();
@@ -853,8 +853,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        if (INTEGRAL_TYPE_P (type)
 	   && get_global_range_query ()->range_of_expr (vr0, @0)
 	   && get_global_range_query ()->range_of_expr (vr1, @1)
-	   && vr0.kind () == VR_RANGE
-	   && vr1.kind () == VR_RANGE)
+	   && !vr0.varying_p () && !vr0.undefined_p ()
+	   && !vr1.varying_p () && !vr1.undefined_p ())
 	 {
 	   wide_int wmin0 = vr0.lower_bound ();
 	   wide_int wmax0 = vr0.upper_bound ();
@@ -3010,7 +3010,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 	value_range vr;
 	if (get_global_range_query ()->range_of_expr (vr, @0)
-	    && vr.kind () == VR_RANGE)
+	    && !vr.varying_p () && !vr.undefined_p ())
           {
 	    wide_int wmin0 = vr.lower_bound ();
 	    wide_int wmax0 = vr.upper_bound ();
diff --git a/gcc/tree-affine.cc b/gcc/tree-affine.cc
index 5d0632f09b8..ee327e63a23 100644
--- a/gcc/tree-affine.cc
+++ b/gcc/tree-affine.cc
@@ -351,7 +351,8 @@ expr_to_aff_combination (aff_tree *comb, tree_code code, tree type,
 		&& TYPE_OVERFLOW_WRAPS (itype)
 		&& TREE_CODE (op1) == INTEGER_CST
 		&& get_range_query (cfun)->range_of_expr (vr, op0)
-		&& vr.kind () == VR_RANGE)
+		&& !vr.varying_p ()
+		&& !vr.undefined_p ())
 	      {
 		wide_int minv = vr.lower_bound ();
 		wide_int maxv = vr.upper_bound ();
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index 4ebd839db15..6a4112b9fde 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -6351,7 +6351,7 @@ dr_step_indicator (struct data_reference *dr, int useful_min)
       value_range vr;
       if (TREE_CODE (step) != SSA_NAME
 	  || !get_range_query (cfun)->range_of_expr (vr, step)
-	  || vr.kind () != VR_RANGE)
+	  || vr.undefined_p ())
 	{
 	  step_min = wi::to_wide (TYPE_MIN_VALUE (type));
 	  step_max = wi::to_wide (TYPE_MAX_VALUE (type));
diff --git a/gcc/tree-dfa.cc b/gcc/tree-dfa.cc
index 82803a8ccb1..ad8cfedec8c 100644
--- a/gcc/tree-dfa.cc
+++ b/gcc/tree-dfa.cc
@@ -542,7 +542,8 @@ get_ref_base_and_extent (tree exp, poly_int64_pod *poffset,
 		    && (unit_size = array_ref_element_size (exp),
 			TREE_CODE (unit_size) == INTEGER_CST)
 		    && query->range_of_expr (vr, index)
-		    && vr.kind () == VR_RANGE)
+		    && !vr.varying_p ()
+		    && !vr.undefined_p ())
 		  {
 		    wide_int min = vr.lower_bound ();
 		    wide_int max = vr.upper_bound ();
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 672cf9fab62..ba47a684f4b 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3032,7 +3032,8 @@ iv_can_overflow_p (class loop *loop, tree type, tree base, tree step)
 
   if (!INTEGRAL_TYPE_P (TREE_TYPE (base))
       || !get_range_query (cfun)->range_of_expr (r, base)
-      || r.kind () != VR_RANGE)
+      || r.varying_p ()
+      || r.undefined_p ())
     return true;
 
   base_min = r.lower_bound ();
@@ -3040,7 +3041,8 @@ iv_can_overflow_p (class loop *loop, tree type, tree base, tree step)
 
   if (!INTEGRAL_TYPE_P (TREE_TYPE (step))
       || !get_range_query (cfun)->range_of_expr (r, step)
-      || r.kind () != VR_RANGE)
+      || r.varying_p ()
+      || r.undefined_p ())
     return true;
 
   step_min = r.lower_bound ();
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 4a3ab8efb71..3b15ffcb0fc 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -687,22 +687,13 @@ two_value_replacement (basic_block cond_bb, basic_block middle_bb,
 	      <= TYPE_PRECISION (TREE_TYPE (lhs)))))
     return false;
 
-  wide_int min, max;
   value_range r;
   get_range_query (cfun)->range_of_expr (r, lhs);
+  if (r.undefined_p ())
+    r.set_varying (TREE_TYPE (lhs));
+  wide_int min = r.lower_bound ();
+  wide_int max = r.upper_bound ();
 
-  if (r.kind () == VR_RANGE)
-    {
-      min = r.lower_bound ();
-      max = r.upper_bound ();
-    }
-  else
-    {
-      int prec = TYPE_PRECISION (TREE_TYPE (lhs));
-      signop sgn = TYPE_SIGN (TREE_TYPE (lhs));
-      min = wi::min_value (prec, sgn);
-      max = wi::max_value (prec, sgn);
-    }
   if (min + 1 != max
       || (wi::to_wide (rhs) != min
 	  && wi::to_wide (rhs) != max))
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index 943936df808..1f7eea93c16 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -3247,7 +3247,8 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
     {
       value_range r;
       if (get_range_query (cfun)->range_of_expr (r, expr->u.nary->op[0])
-	  && r.kind () == VR_RANGE
+	  && !r.undefined_p ()
+	  && !r.varying_p ()
 	  && !wi::neg_p (r.lower_bound (), SIGNED)
 	  && !wi::neg_p (r.upper_bound (), SIGNED))
 	{
diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc
index e795bdc0db4..aeaca2f76cc 100644
--- a/gcc/tree-ssa-reassoc.cc
+++ b/gcc/tree-ssa-reassoc.cc
@@ -3372,7 +3372,8 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
       value_range r;
       if (TREE_CODE (exp) == SSA_NAME
 	  && get_range_query (cfun)->range_of_expr (r, exp)
-	  && r.kind () == VR_RANGE
+	  && !r.undefined_p ()
+	  && !r.varying_p ()
 	  && wi::leu_p (r.upper_bound () - r.lower_bound (), prec - 1))
 	{
 	  wide_int min = r.lower_bound ();
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index dcc9e9e14ab..0bbcb04834f 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -350,18 +350,19 @@ compare_nonzero_chars (strinfo *si, gimple *stmt,
     return -1;
 
   value_range vr;
-  if (!rvals->range_of_expr (vr, si->nonzero_chars, stmt))
-    return -1;
-  value_range_kind rng = vr.kind ();
-  if (rng != VR_RANGE)
+  if (!rvals->range_of_expr (vr, si->nonzero_chars, stmt)
+      || vr.varying_p ()
+      || vr.undefined_p ())
     return -1;
 
   /* If the offset is less than the minimum length or if the bounds
      of the length range are equal return the result of the comparison
      same as in the constant case.  Otherwise return a conservative
      result.  */
-  int cmpmin = compare_tree_int (vr.min (), off);
-  if (cmpmin > 0 || tree_int_cst_equal (vr.min (), vr.max ()))
+  tree lower = wide_int_to_tree (vr.type (), vr.lower_bound ());
+  tree upper = wide_int_to_tree (vr.type (), vr.upper_bound ());
+  int cmpmin = compare_tree_int (lower, off);
+  if (cmpmin > 0 || tree_int_cst_equal (lower, upper))
     return cmpmin;
 
   return -1;
diff --git a/gcc/tree-switch-conversion.cc b/gcc/tree-switch-conversion.cc
index dfdcd79bb40..44934d2560d 100644
--- a/gcc/tree-switch-conversion.cc
+++ b/gcc/tree-switch-conversion.cc
@@ -1590,7 +1590,8 @@ bit_test_cluster::emit (tree index_expr, tree index_type,
   value_range r;
   if (TREE_CODE (index_expr) == SSA_NAME
       && get_range_query (cfun)->range_of_expr (r, index_expr)
-      && r.kind () == VR_RANGE
+      && !r.undefined_p ()
+      && !r.varying_p ()
       && wi::leu_p (r.upper_bound () - r.lower_bound (), prec - 1))
     {
       wide_int min = r.lower_bound ();
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index b964dcb8ad9..33a8b2bb606 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -4598,7 +4598,7 @@ vect_recog_divmod_pattern (vec_info *vinfo,
       int msb = 1;
       value_range r;
       get_range_query (cfun)->range_of_expr (r, oprnd0);
-      if (r.kind () == VR_RANGE)
+      if (!r.varying_p () && !r.undefined_p ())
 	{
 	  if (!wi::neg_p (r.lower_bound (), TYPE_SIGN (itype)))
 	    msb = 0;
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 8394ff0f837..ead4248b8e5 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -14296,7 +14296,8 @@ get_range_pos_neg (tree arg)
   if (TREE_CODE (arg) != SSA_NAME)
     return 3;
   value_range r;
-  while (!get_global_range_query ()->range_of_expr (r, arg) || r.kind () != VR_RANGE)
+  while (!get_global_range_query ()->range_of_expr (r, arg)
+	 || r.undefined_p () || r.varying_p ())
     {
       gimple *g = SSA_NAME_DEF_STMT (arg);
       if (is_gimple_assign (g)
-- 
2.40.0


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

* [COMMITTED] Convert compare_nonzero_chars to wide_ints.
  2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Replace ad-hoc value_range dumpers with irange::dump Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Remove some uses of deprecated irange API Aldy Hernandez
@ 2023-04-26 11:47 ` Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Remove range_int_cst_p Aldy Hernandez
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* tree-ssa-strlen.cc (compare_nonzero_chars): Convert to wide_ints.
---
 gcc/tree-ssa-strlen.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index 0bbcb04834f..de785281b27 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -359,10 +359,10 @@ compare_nonzero_chars (strinfo *si, gimple *stmt,
      of the length range are equal return the result of the comparison
      same as in the constant case.  Otherwise return a conservative
      result.  */
-  tree lower = wide_int_to_tree (vr.type (), vr.lower_bound ());
-  tree upper = wide_int_to_tree (vr.type (), vr.upper_bound ());
-  int cmpmin = compare_tree_int (lower, off);
-  if (cmpmin > 0 || tree_int_cst_equal (lower, upper))
+  signop sign = TYPE_SIGN (vr.type ());
+  unsigned prec = TYPE_PRECISION (vr.type ());
+  int cmpmin = wi::cmp (vr.lower_bound (), wi::uhwi (off, prec), sign);
+  if (cmpmin > 0 || vr.singleton_p ())
     return cmpmin;
 
   return -1;
-- 
2.40.0


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

* [COMMITTED] Remove range_int_cst_p.
  2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
                   ` (2 preceding siblings ...)
  2023-04-26 11:47 ` [COMMITTED] Convert compare_nonzero_chars to wide_ints Aldy Hernandez
@ 2023-04-26 11:47 ` Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Remove range_has_numeric_bounds_p Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Remove legacy range support Aldy Hernandez
  5 siblings, 0 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* tree-data-ref.cc (compute_distributive_range): Replace uses of
	range_int_cst_p with irange API.
	* tree-ssa-strlen.cc (get_range_strlen_dynamic): Same.
	* tree-vrp.h (range_int_cst_p): Delete.
	* vr-values.cc (check_for_binary_op_overflow): Replace usees of
	range_int_cst_p with irange API.
	(vr_set_zero_nonzero_bits): Same.
	(range_fits_type_p): Same.
	(simplify_using_ranges::simplify_casted_cond): Same.
---
 gcc/tree-data-ref.cc   |  3 ++-
 gcc/tree-ssa-strlen.cc | 28 ++++++++++----------
 gcc/tree-vrp.cc        |  9 -------
 gcc/tree-vrp.h         |  2 --
 gcc/vr-values.cc       | 59 ++++++++++++++++++++++--------------------
 5 files changed, 48 insertions(+), 53 deletions(-)

diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index 6a4112b9fde..b3a1d410cbd 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -646,7 +646,8 @@ compute_distributive_range (tree type, value_range &op0_range,
   if (!op.fold_range (wide_range, ssizetype, op0_range, op1_range))
     wide_range.set_varying (ssizetype);;
   flag_wrapv = saved_flag_wrapv;
-  if (wide_range.num_pairs () != 1 || !range_int_cst_p (&wide_range))
+  if (wide_range.num_pairs () != 1
+      || wide_range.varying_p () || wide_range.undefined_p ())
     return false;
 
   wide_int lb = wide_range.lower_bound ();
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index de785281b27..4bf183072d9 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -1222,13 +1222,14 @@ get_range_strlen_dynamic (tree src, gimple *stmt,
 	    {
 	      value_range vr;
 	      ptr_qry->rvals->range_of_expr (vr, si->nonzero_chars, si->stmt);
-	      if (range_int_cst_p (&vr))
+	      if (vr.undefined_p () || vr.varying_p ())
+		pdata->minlen = build_zero_cst (size_type_node);
+	      else
 		{
-		  pdata->minlen = vr.min ();
-		  pdata->maxlen = vr.max ();
+		  tree type = vr.type ();
+		  pdata->minlen = wide_int_to_tree (type, vr.lower_bound ());
+		  pdata->maxlen = wide_int_to_tree (type, vr.upper_bound ());
 		}
-	      else
-		pdata->minlen = build_zero_cst (size_type_node);
 	    }
 	  else
 	    pdata->minlen = build_zero_cst (size_type_node);
@@ -1266,21 +1267,22 @@ get_range_strlen_dynamic (tree src, gimple *stmt,
 	{
 	  value_range vr;
 	  ptr_qry->rvals->range_of_expr (vr, si->nonzero_chars, stmt);
-	  if (range_int_cst_p (&vr))
+	  if (vr.varying_p () || vr.undefined_p ())
+	    {
+	      pdata->minlen = build_zero_cst (size_type_node);
+	      pdata->maxlen = build_all_ones_cst (size_type_node);
+	    }
+	  else
 	    {
-	      pdata->minlen = vr.min ();
-	      pdata->maxlen = vr.max ();
+	      tree type = vr.type ();
+	      pdata->minlen = wide_int_to_tree (type, vr.lower_bound ());
+	      pdata->maxlen = wide_int_to_tree (type, vr.upper_bound ());
 	      offset_int max = offset_int::from (vr.upper_bound (0), SIGNED);
 	      if (tree maxbound = get_maxbound (si->ptr, stmt, max, ptr_qry))
 		pdata->maxbound = maxbound;
 	      else
 		pdata->maxbound = pdata->maxlen;
 	    }
-	  else
-	    {
-	      pdata->minlen = build_zero_cst (size_type_node);
-	      pdata->maxlen = build_all_ones_cst (size_type_node);
-	    }
 	}
       else if (pdata->minlen && TREE_CODE (pdata->minlen) == INTEGER_CST)
 	{
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 27126088708..6c6e0382809 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -312,15 +312,6 @@ intersect_range_with_nonzero_bits (enum value_range_kind vr_type,
   return vr_type;
 }
 
-/* Return true if max and min of VR are INTEGER_CST.  It's not necessary
-   a singleton.  */
-
-bool
-range_int_cst_p (const value_range *vr)
-{
-  return (vr->kind () == VR_RANGE && range_has_numeric_bounds_p (vr));
-}
-
 /* Return the single symbol (an SSA_NAME) contained in T if any, or NULL_TREE
    otherwise.  We only handle additive operations and set NEG to true if the
    symbol is negated and INV to the invariant part, if any.  */
diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h
index bad50e31aad..58216388ee6 100644
--- a/gcc/tree-vrp.h
+++ b/gcc/tree-vrp.h
@@ -22,8 +22,6 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "value-range.h"
 
-extern bool range_int_cst_p (const value_range *);
-
 extern int compare_values (tree, tree);
 extern int compare_values_warnv (tree, tree, bool *);
 extern int operand_less_p (tree, tree);
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index f43de63b4f4..ea7c6738739 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -125,16 +125,16 @@ check_for_binary_op_overflow (range_query *query,
     vr1.set_varying (TREE_TYPE (op1));
 
   tree vr0min, vr0max, vr1min, vr1max;
-  get_legacy_range (vr0, vr0min, vr0max);
-  get_legacy_range (vr1, vr1min, vr1max);
-  if (!range_int_cst_p (&vr0)
+  value_range_kind kind0 = get_legacy_range (vr0, vr0min, vr0max);
+  value_range_kind kind1 = get_legacy_range (vr1, vr1min, vr1max);
+  if (kind0 != VR_RANGE
       || TREE_OVERFLOW (vr0min)
       || TREE_OVERFLOW (vr0max))
     {
       vr0min = vrp_val_min (TREE_TYPE (op0));
       vr0max = vrp_val_max (TREE_TYPE (op0));
     }
-  if (!range_int_cst_p (&vr1)
+  if (kind1 != VR_RANGE
       || TREE_OVERFLOW (vr1min)
       || TREE_OVERFLOW (vr1max))
     {
@@ -1000,10 +1000,11 @@ simplify_using_ranges::simplify_div_or_mod_using_ranges
     {
       if (!query->range_of_expr (vr, op0, stmt))
 	vr.set_varying (TREE_TYPE (op0));
-      if (range_int_cst_p (&vr))
+      if (!vr.varying_p () && !vr.undefined_p ())
 	{
-	  op0min = vr.min ();
-	  op0max = vr.max ();
+	  tree type = vr.type ();
+	  op0min = wide_int_to_tree (type, vr.lower_bound ());
+	  op0max = wide_int_to_tree (type, vr.upper_bound ());
 	}
     }
 
@@ -1013,8 +1014,8 @@ simplify_using_ranges::simplify_div_or_mod_using_ranges
       value_range vr1;
       if (!query->range_of_expr (vr1, op1, stmt))
 	vr1.set_varying (TREE_TYPE (op1));
-      if (range_int_cst_p (&vr1))
-	op1min = vr1.min ();
+      if (!vr1.varying_p () && !vr1.undefined_p ())
+	op1min = wide_int_to_tree (vr1.type (), vr1.lower_bound ());
     }
   if (rhs_code == TRUNC_MOD_EXPR
       && TREE_CODE (op1min) == INTEGER_CST
@@ -1217,21 +1218,19 @@ simplify_using_ranges::simplify_abs_using_ranges (gimple_stmt_iterator *gsi,
 
 static bool
 vr_set_zero_nonzero_bits (const tree expr_type,
-			  const value_range *vr,
+			  const irange *vr,
 			  wide_int *may_be_nonzero,
 			  wide_int *must_be_nonzero)
 {
-  if (range_int_cst_p (vr))
+  if (vr->varying_p () || vr->undefined_p ())
     {
-      wi_set_zero_nonzero_bits (expr_type,
-				wi::to_wide (vr->min ()),
-				wi::to_wide (vr->max ()),
-				*may_be_nonzero, *must_be_nonzero);
-      return true;
+      *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type));
+      *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type));
+      return false;
     }
-  *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type));
-  *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type));
-  return false;
+  wi_set_zero_nonzero_bits (expr_type, vr->lower_bound (), vr->upper_bound (),
+			    *may_be_nonzero, *must_be_nonzero);
+  return true;
 }
 
 /* Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR.
@@ -1418,7 +1417,9 @@ range_fits_type_p (const value_range *vr,
     return true;
 
   /* Now we can only handle ranges with constant bounds.  */
-  if (!range_int_cst_p (vr))
+  tree vrmin, vrmax;
+  value_range_kind kind = get_legacy_range (*vr, vrmin, vrmax);
+  if (kind != VR_RANGE)
     return false;
 
   /* For sign changes, the MSB of the wide_int has to be clear.
@@ -1426,17 +1427,17 @@ range_fits_type_p (const value_range *vr,
      a signed wide_int, while a negative value cannot be represented
      by an unsigned wide_int.  */
   if (src_sgn != dest_sgn
-      && (wi::lts_p (wi::to_wide (vr->min ()), 0)
-	  || wi::lts_p (wi::to_wide (vr->max ()), 0)))
+      && (wi::lts_p (wi::to_wide (vrmin), 0)
+	  || wi::lts_p (wi::to_wide (vrmax), 0)))
     return false;
 
   /* Then we can perform the conversion on both ends and compare
      the result for equality.  */
-  tem = wi::ext (wi::to_widest (vr->min ()), dest_precision, dest_sgn);
-  if (tem != wi::to_widest (vr->min ()))
+  tem = wi::ext (wi::to_widest (vrmin), dest_precision, dest_sgn);
+  if (tem != wi::to_widest (vrmin))
     return false;
-  tem = wi::ext (wi::to_widest (vr->max ()), dest_precision, dest_sgn);
-  if (tem != wi::to_widest (vr->max ()))
+  tem = wi::ext (wi::to_widest (vrmax), dest_precision, dest_sgn);
+  if (tem != wi::to_widest (vrmax))
     return false;
 
   return true;
@@ -1682,7 +1683,8 @@ simplify_using_ranges::simplify_casted_cond (gcond *stmt)
 	  value_range vr;
 
 	  if (query->range_of_expr (vr, innerop)
-	      && range_int_cst_p (&vr)
+	      && !vr.varying_p ()
+	      && !vr.undefined_p ()
 	      && range_fits_type_p (&vr,
 				    TYPE_PRECISION (TREE_TYPE (op0)),
 				    TYPE_SIGN (TREE_TYPE (op0)))
@@ -2024,7 +2026,8 @@ simplify_using_ranges::simplify_float_conversion_using_ranges
 
   /* We can only handle constant ranges.  */
   if (!query->range_of_expr (vr, rhs1, stmt)
-      || !range_int_cst_p (&vr))
+      || vr.varying_p ()
+      || vr.undefined_p ())
     return false;
 
   /* First check if we can use a signed type in place of an unsigned.  */
-- 
2.40.0


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

* [COMMITTED] Remove range_has_numeric_bounds_p.
  2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
                   ` (3 preceding siblings ...)
  2023-04-26 11:47 ` [COMMITTED] Remove range_int_cst_p Aldy Hernandez
@ 2023-04-26 11:47 ` Aldy Hernandez
  2023-04-26 11:47 ` [COMMITTED] Remove legacy range support Aldy Hernandez
  5 siblings, 0 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* value-range.cc (irange::copy_legacy_to_multi_range): Rewrite use
	of range_has_numeric_bounds_p with irange API.
	(range_has_numeric_bounds_p): Delete.
	* value-range.h (range_has_numeric_bounds_p): Delete.
---
 gcc/value-range.cc | 12 +++---------
 gcc/value-range.h  |  1 -
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index da9098139ad..f7c3e7a00e2 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -979,7 +979,9 @@ irange::copy_legacy_to_multi_range (const irange &src)
     set_varying (src.type ());
   else
     {
-      if (range_has_numeric_bounds_p (&src))
+      if (!src.undefined_p ()
+	  && TREE_CODE (src.min ()) == INTEGER_CST
+	  && TREE_CODE (src.max ()) == INTEGER_CST)
 	set (src.min (), src.max (), src.kind ());
       else
 	{
@@ -3068,14 +3070,6 @@ ranges_from_anti_range (const value_range *ar,
   return !vr0->undefined_p ();
 }
 
-bool
-range_has_numeric_bounds_p (const irange *vr)
-{
-  return (!vr->undefined_p ()
-	  && TREE_CODE (vr->min ()) == INTEGER_CST
-	  && TREE_CODE (vr->max ()) == INTEGER_CST);
-}
-
 /* Return whether VAL is equal to the maximum value of its type.
    We can't do a simple equality comparison with TYPE_MAX_VALUE because
    C typedefs and Ada subtypes can produce types whose TYPE_MAX_VALUE
diff --git a/gcc/value-range.h b/gcc/value-range.h
index c1474a73eaf..b47540d49be 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -669,7 +669,6 @@ irange::legacy_mode_p () const
   return m_max_ranges == 1;
 }
 
-extern bool range_has_numeric_bounds_p (const irange *);
 extern bool ranges_from_anti_range (const value_range *,
 				    value_range *, value_range *);
 extern value_range_kind get_legacy_range (const irange &, tree &min, tree &max);
-- 
2.40.0


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

* [COMMITTED] Remove legacy range support.
  2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
                   ` (4 preceding siblings ...)
  2023-04-26 11:47 ` [COMMITTED] Remove range_has_numeric_bounds_p Aldy Hernandez
@ 2023-04-26 11:47 ` Aldy Hernandez
  5 siblings, 0 replies; 7+ messages in thread
From: Aldy Hernandez @ 2023-04-26 11:47 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

This patch removes all the code paths guarded by legacy_mode_p(), thus
allowing us to re-use the int_range<1> idiom for a range of one
sub-range.  This allows us to represent these simple ranges in a more
efficient manner.

gcc/ChangeLog:

	* range-op.cc (range_op_cast_tests): Remove legacy support.
	* value-range-storage.h (vrange_allocator::alloc_irange): Same.
	* value-range.cc (irange::operator=): Same.
	(get_legacy_range): Same.
	(irange::copy_legacy_to_multi_range): Delete.
	(irange::copy_to_legacy): Delete.
	(irange::irange_set_anti_range): Delete.
	(irange::set): Remove legacy support.
	(irange::verify_range): Same.
	(irange::legacy_lower_bound): Delete.
	(irange::legacy_upper_bound): Delete.
	(irange::legacy_equal_p): Delete.
	(irange::operator==): Remove legacy support.
	(irange::singleton_p): Same.
	(irange::value_inside_range): Same.
	(irange::contains_p): Same.
	(intersect_ranges): Delete.
	(irange::legacy_intersect): Delete.
	(union_ranges): Delete.
	(irange::legacy_union): Delete.
	(irange::legacy_verbose_union_): Delete.
	(irange::legacy_verbose_intersect): Delete.
	(irange::irange_union): Remove legacy support.
	(irange::irange_intersect): Same.
	(irange::intersect): Same.
	(irange::invert): Same.
	(ranges_from_anti_range): Delete.
	(gt_pch_nx): Adjust for legacy removal.
	(gt_ggc_mx): Same.
	(range_tests_legacy): Delete.
	(range_tests_misc): Adjust for legacy removal.
	(range_tests): Same.
	* value-range.h (class irange): Same.
	(irange::legacy_mode_p): Delete.
	(ranges_from_anti_range): Delete.
	(irange::nonzero_p): Adjust for legacy removal.
	(irange::lower_bound): Same.
	(irange::upper_bound): Same.
	(irange::union_): Same.
	(irange::intersect): Same.
	(irange::set_nonzero): Same.
	(irange::set_zero): Same.
	* vr-values.cc (simplify_using_ranges::legacy_fold_cond_overflow): Same.
---
 gcc/range-op.cc           |    2 +-
 gcc/value-range-storage.h |    3 +-
 gcc/value-range.cc        | 1188 ++-----------------------------------
 gcc/value-range.h         |   64 +-
 gcc/vr-values.cc          |    4 +-
 5 files changed, 47 insertions(+), 1214 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index e47edcf3d74..215a1613b38 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4890,7 +4890,7 @@ namespace selftest
 static void
 range_op_cast_tests ()
 {
-  int_range<1> r0, r1, r2, rold;
+  int_range<2> r0, r1, r2, rold;
   r0.set_varying (integer_type_node);
   tree maxint = wide_int_to_tree (integer_type_node, r0.upper_bound ());
 
diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h
index 6da377ebd2e..070b85c5739 100644
--- a/gcc/value-range-storage.h
+++ b/gcc/value-range-storage.h
@@ -175,8 +175,7 @@ inline irange *
 vrange_allocator::alloc_irange (unsigned num_pairs)
 {
   // Never allocate 0 pairs.
-  // Don't allocate 1 either, or we get legacy value_range's.
-  if (num_pairs < 2)
+  if (num_pairs < 1)
     num_pairs = 2;
 
   size_t nbytes = sizeof (tree) * 2 * num_pairs;
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index f7c3e7a00e2..1a3013be6fd 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -877,23 +877,11 @@ frange::set_nonnegative (tree type)
   set (type, dconst0, frange_val_max (type));
 }
 
-// Here we copy between any two irange's.  The ranges can be legacy or
-// multi-ranges, and copying between any combination works correctly.
+// Here we copy between any two irange's.
 
 irange &
 irange::operator= (const irange &src)
 {
-  if (legacy_mode_p ())
-    {
-      copy_to_legacy (src);
-      return *this;
-    }
-  if (src.legacy_mode_p ())
-    {
-      copy_legacy_to_multi_range (src);
-      return *this;
-    }
-
   unsigned x;
   unsigned lim = src.m_num_ranges;
   if (lim > m_max_ranges)
@@ -909,6 +897,8 @@ irange::operator= (const irange &src)
   m_num_ranges = lim;
   m_kind = src.m_kind;
   m_nonzero_mask = src.m_nonzero_mask;
+  if (m_max_ranges == 1)
+    normalize_kind ();
   if (flag_checking)
     verify_range ();
   return *this;
@@ -951,12 +941,6 @@ get_legacy_range (const irange &r, tree &min, tree &max)
       inv.invert ();
       min = wide_int_to_tree (type, inv.lower_bound (0));
       max = wide_int_to_tree (type, inv.upper_bound (0));
-      if (r.legacy_mode_p ())
-	{
-	  gcc_checking_assert (old_kind == VR_ANTI_RANGE);
-	  gcc_checking_assert (vrp_operand_equal_p (old_min, min));
-	  gcc_checking_assert (vrp_operand_equal_p (old_max, max));
-	}
       return VR_ANTI_RANGE;
     }
 
@@ -968,54 +952,6 @@ get_legacy_range (const irange &r, tree &min, tree &max)
   return VR_RANGE;
 }
 
-void
-irange::copy_legacy_to_multi_range (const irange &src)
-{
-  gcc_checking_assert (src.legacy_mode_p ());
-  gcc_checking_assert (!legacy_mode_p ());
-  if (src.undefined_p ())
-    set_undefined ();
-  else if (src.varying_p ())
-    set_varying (src.type ());
-  else
-    {
-      if (!src.undefined_p ()
-	  && TREE_CODE (src.min ()) == INTEGER_CST
-	  && TREE_CODE (src.max ()) == INTEGER_CST)
-	set (src.min (), src.max (), src.kind ());
-      else
-	{
-	  value_range cst (src);
-	  gcc_checking_assert (cst.varying_p () || cst.kind () == VR_RANGE);
-	  set (cst.min (), cst.max ());
-	}
-    }
-}
-
-// Copy any type of irange into a legacy.
-
-void
-irange::copy_to_legacy (const irange &src)
-{
-  gcc_checking_assert (legacy_mode_p ());
-  // Handle legacy to legacy and other things that are easy to copy.
-  if (src.legacy_mode_p () || src.varying_p () || src.undefined_p ())
-    {
-      m_num_ranges = src.m_num_ranges;
-      m_base[0] = src.m_base[0];
-      m_base[1] = src.m_base[1];
-      m_kind = src.m_kind;
-      m_nonzero_mask = src.m_nonzero_mask;
-      return;
-    }
-  // Copy multi-range to legacy.
-  tree min, max;
-  if (get_legacy_range (src, min, max) == VR_ANTI_RANGE)
-    set (min, max, VR_ANTI_RANGE);
-  else
-    set (src.tree_lower_bound (), src.tree_upper_bound ());
-}
-
 void
 irange::irange_set (tree min, tree max)
 {
@@ -1092,6 +1028,11 @@ irange::irange_set_anti_range (tree min, tree max)
   wide_int w_max = wi::to_wide (max);
   if (wi::ne_p (w_max, type_range.upper_bound ()))
     {
+      if (m_max_ranges == 1 && m_num_ranges)
+	{
+	  set_varying (type);
+	  return;
+	}
       wide_int lim2 = wi::add (w_max, 1, sign, &ovf);
       gcc_checking_assert (ovf != wi::OVF_OVERFLOW);
       m_base[m_num_ranges * 2] = wide_int_to_tree (type, lim2);
@@ -1138,65 +1079,13 @@ irange::set (tree min, tree max, value_range_kind kind)
   if (TREE_OVERFLOW_P (max))
     max = drop_tree_overflow (max);
 
-  if (!legacy_mode_p ())
-    {
-      if (kind == VR_RANGE)
-	irange_set (min, max);
-      else
-	{
-	  gcc_checking_assert (kind == VR_ANTI_RANGE);
-	  irange_set_anti_range (min, max);
-	}
-      return;
-    }
-
-  // Symbolics are not allowed in an irange.
-  gcc_checking_assert (TREE_CODE (min) == INTEGER_CST
-		       && TREE_CODE (max) == INTEGER_CST);
-
-  // Anti-ranges that can be represented as ranges should be so.
-  if (kind == VR_ANTI_RANGE)
+  if (kind == VR_RANGE)
+    irange_set (min, max);
+  else
     {
-      bool is_min = vrp_val_is_min (min);
-      bool is_max = vrp_val_is_max (max);
-
-      if (is_min && is_max)
-	{
-	  // Fall through.  This will either be normalized as
-	  // VR_UNDEFINED if the anti-range spans the entire
-	  // precision, or it will remain an VR_ANTI_RANGE in the case
-	  // of an -fstrict-enum where [MIN,MAX] is less than the span
-	  // of underlying precision.
-	}
-      else if (TYPE_PRECISION (TREE_TYPE (min)) == 1)
-	{
-	  irange_set_1bit_anti_range (min, max);
-	  return;
-	}
-      else if (is_min)
-        {
-	  tree one = build_int_cst (TREE_TYPE (max), 1);
-	  min = int_const_binop (PLUS_EXPR, max, one);
-	  max = vrp_val_max (TREE_TYPE (max));
-	  kind = VR_RANGE;
-        }
-      else if (is_max)
-        {
-	  tree one = build_int_cst (TREE_TYPE (min), 1);
-	  max = int_const_binop (MINUS_EXPR, min, one);
-	  min = vrp_val_min (TREE_TYPE (min));
-	  kind = VR_RANGE;
-        }
+      gcc_checking_assert (kind == VR_ANTI_RANGE);
+      irange_set_anti_range (min, max);
     }
-
-  m_kind = kind;
-  m_base[0] = min;
-  m_base[1] = max;
-  m_num_ranges = 1;
-  m_nonzero_mask = NULL;
-  normalize_kind ();
-  if (flag_checking)
-    verify_range ();
 }
 
 // Check the validity of the range.
@@ -1210,6 +1099,7 @@ irange::verify_range ()
       gcc_checking_assert (m_num_ranges == 0);
       return;
     }
+  gcc_checking_assert (m_num_ranges <= m_max_ranges);
   if (m_kind == VR_VARYING)
     {
       gcc_checking_assert (!m_nonzero_mask
@@ -1218,106 +1108,20 @@ irange::verify_range ()
       gcc_checking_assert (varying_compatible_p ());
       return;
     }
-  if (!legacy_mode_p ())
-    {
-      gcc_checking_assert (m_num_ranges != 0);
-      gcc_checking_assert (!varying_compatible_p ());
-      for (unsigned i = 0; i < m_num_ranges; ++i)
-	{
-	  tree lb = tree_lower_bound (i);
-	  tree ub = tree_upper_bound (i);
-	  int c = compare_values (lb, ub);
-	  gcc_checking_assert (c == 0 || c == -1);
-	}
-      return;
-    }
-  if (m_kind == VR_RANGE || m_kind == VR_ANTI_RANGE)
-    {
-      gcc_checking_assert (m_num_ranges == 1);
-      int cmp = compare_values (tree_lower_bound (0), tree_upper_bound (0));
-      gcc_checking_assert (cmp == 0 || cmp == -1 || cmp == -2);
-    }
-}
-
-// Return the lower bound for a sub-range.  PAIR is the sub-range in
-// question.
-
-wide_int
-irange::legacy_lower_bound (unsigned pair) const
-{
-  gcc_checking_assert (legacy_mode_p ());
-  gcc_checking_assert (m_num_ranges > 0);
-  gcc_checking_assert (pair + 1 <= num_pairs ());
-  if (m_kind == VR_ANTI_RANGE)
-    {
-      tree typ = type (), t;
-      if (pair == 1 || 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 the upper bound for a sub-range.  PAIR is the sub-range in
-// question.
-
-wide_int
-irange::legacy_upper_bound (unsigned pair) const
-{
-  gcc_checking_assert (legacy_mode_p ());
-  gcc_checking_assert (m_num_ranges > 0);
-  gcc_checking_assert (pair + 1 <= num_pairs ());
-  if (m_kind == VR_ANTI_RANGE)
+  gcc_checking_assert (m_num_ranges != 0);
+  gcc_checking_assert (!varying_compatible_p ());
+  for (unsigned i = 0; i < m_num_ranges; ++i)
     {
-      tree typ = type (), t;
-      if (pair == 1 || vrp_val_is_min (min ()))
-	t = vrp_val_max (typ);
-      else
-	t = wide_int_to_tree (typ, wi::to_wide (min ()) - 1);
-      return wi::to_wide (t);
+      tree lb = tree_lower_bound (i);
+      tree ub = tree_upper_bound (i);
+      int c = compare_values (lb, ub);
+      gcc_checking_assert (c == 0 || c == -1);
     }
-  return wi::to_wide (tree_upper_bound (pair));
-}
-
-bool
-irange::legacy_equal_p (const irange &other) const
-{
-  gcc_checking_assert (legacy_mode_p () && other.legacy_mode_p ());
-
-  if (m_kind != other.m_kind)
-   return false;
-  if (m_kind == VR_UNDEFINED)
-    return true;
-  if (m_kind == VR_VARYING)
-    return range_compatible_p (type (), other.type ());
-  return (vrp_operand_equal_p (tree_lower_bound (0),
-			       other.tree_lower_bound (0))
-	  && vrp_operand_equal_p (tree_upper_bound (0),
-				  other.tree_upper_bound (0))
-	  && (widest_int::from (get_nonzero_bits (),
-				TYPE_SIGN (type ()))
-	      == widest_int::from (other.get_nonzero_bits (),
-				   TYPE_SIGN (other.type ()))));
 }
 
 bool
 irange::operator== (const irange &other) const
 {
-  if (legacy_mode_p ())
-    {
-      if (other.legacy_mode_p ())
-	return legacy_equal_p (other);
-      value_range tmp (other);
-      return legacy_equal_p (tmp);
-    }
-  if (other.legacy_mode_p ())
-    {
-      value_range tmp2 (*this);
-      return tmp2.legacy_equal_p (other);
-    }
-
   if (m_num_ranges != other.m_num_ranges)
     return false;
 
@@ -1348,43 +1152,11 @@ irange::operator== (const irange &other) const
 bool
 irange::singleton_p (tree *result) const
 {
-  if (!legacy_mode_p ())
-    {
-      if (num_pairs () == 1 && (wi::to_wide (tree_lower_bound ())
-				== wi::to_wide (tree_upper_bound ())))
-	{
-	  if (result)
-	    *result = tree_lower_bound ();
-	  return true;
-	}
-      return false;
-    }
-  if (m_kind == VR_ANTI_RANGE)
-    {
-      if (nonzero_p ())
-	{
-	  if (TYPE_PRECISION (type ()) == 1)
-	    {
-	      if (result)
-		*result = max ();
-	      return true;
-	    }
-	  return false;
-	}
-      if (num_pairs () == 1)
-	{
-	  value_range vr0, vr1;
-	  ranges_from_anti_range ((const value_range *) this, &vr0, &vr1);
-	  return vr0.singleton_p (result);
-	}
-    }
-  // Catches non-numeric extremes as well.
-  if (m_kind == VR_RANGE
-      && vrp_operand_equal_p (min (), max ())
-      && is_gimple_min_invariant (min ()))
+  if (num_pairs () == 1 && (wi::to_wide (tree_lower_bound ())
+			    == wi::to_wide (tree_upper_bound ())))
     {
       if (result)
-        *result = min ();
+	*result = tree_lower_bound ();
       return true;
     }
   return false;
@@ -1406,7 +1178,10 @@ irange::value_inside_range (tree val) const
   if (undefined_p ())
     return 0;
 
-  if (!legacy_mode_p () && TREE_CODE (val) == INTEGER_CST)
+  gcc_checking_assert (TREE_CODE (val) == INTEGER_CST);
+
+  // FIXME:
+  if (TREE_CODE (val) == INTEGER_CST)
     return contains_p (val);
 
   int cmp1 = operand_less_p (val, min ());
@@ -1439,12 +1214,6 @@ irange::contains_p (tree cst) const
   if (undefined_p ())
     return false;
 
-  if (legacy_mode_p ())
-    {
-      gcc_checking_assert (TREE_CODE (cst) == INTEGER_CST);
-      return value_inside_range (cst) == 1;
-    }
-
   gcc_checking_assert (TREE_CODE (cst) == INTEGER_CST);
 
   // See if we can exclude CST based on the nonzero bits.
@@ -1468,792 +1237,6 @@ irange::contains_p (tree cst) const
   return false;
 }
 
-/* Intersect the two value-ranges { *VR0TYPE, *VR0MIN, *VR0MAX } and
-   { VR1TYPE, VR0MIN, VR0MAX } and store the result
-   in { *VR0TYPE, *VR0MIN, *VR0MAX }.  This may not be the smallest
-   possible such range.  The resulting range is not canonicalized.  */
-
-static void
-intersect_ranges (enum value_range_kind *vr0type,
-		  tree *vr0min, tree *vr0max,
-		  enum value_range_kind vr1type,
-		  tree vr1min, tree vr1max)
-{
-  bool mineq = vrp_operand_equal_p (*vr0min, vr1min);
-  bool maxeq = vrp_operand_equal_p (*vr0max, vr1max);
-
-  /* [] is vr0, () is vr1 in the following classification comments.  */
-  if (mineq && maxeq)
-    {
-      /* [(  )] */
-      if (*vr0type == vr1type)
-	/* Nothing to do for equal ranges.  */
-	;
-      else if ((*vr0type == VR_RANGE
-		&& vr1type == VR_ANTI_RANGE)
-	       || (*vr0type == VR_ANTI_RANGE
-		   && vr1type == VR_RANGE))
-	{
-	  /* For anti-range with range intersection the result is empty.  */
-	  *vr0type = VR_UNDEFINED;
-	  *vr0min = NULL_TREE;
-	  *vr0max = NULL_TREE;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if (operand_less_p (*vr0max, vr1min) == 1
-	   || operand_less_p (vr1max, *vr0min) == 1)
-    {
-      /* [ ] ( ) or ( ) [ ]
-	 If the ranges have an empty intersection, the result of the
-	 intersect operation is the range for intersecting an
-	 anti-range with a range or empty when intersecting two ranges.  */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_ANTI_RANGE)
-	;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  *vr0type = vr1type;
-	  *vr0min = vr1min;
-	  *vr0max = vr1max;
-	}
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  *vr0type = VR_UNDEFINED;
-	  *vr0min = NULL_TREE;
-	  *vr0max = NULL_TREE;
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  /* If the anti-ranges are adjacent to each other merge them.  */
-	  if (TREE_CODE (*vr0max) == INTEGER_CST
-	      && TREE_CODE (vr1min) == INTEGER_CST
-	      && operand_less_p (*vr0max, vr1min) == 1
-	      && integer_onep (int_const_binop (MINUS_EXPR,
-						vr1min, *vr0max)))
-	    *vr0max = vr1max;
-	  else if (TREE_CODE (vr1max) == INTEGER_CST
-		   && TREE_CODE (*vr0min) == INTEGER_CST
-		   && operand_less_p (vr1max, *vr0min) == 1
-		   && integer_onep (int_const_binop (MINUS_EXPR,
-						     *vr0min, vr1max)))
-	    *vr0min = vr1min;
-	  /* Else arbitrarily take VR0.  */
-	}
-    }
-  else if ((maxeq || operand_less_p (vr1max, *vr0max) == 1)
-	   && (mineq || operand_less_p (*vr0min, vr1min) == 1))
-    {
-      /* [ (  ) ] or [(  ) ] or [ (  )] */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_RANGE)
-	{
-	  /* If both are ranges the result is the inner one.  */
-	  *vr0type = vr1type;
-	  *vr0min = vr1min;
-	  *vr0max = vr1max;
-	}
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  /* Choose the right gap if the left one is empty.  */
-	  if (mineq)
-	    {
-	      if (TREE_CODE (vr1max) != INTEGER_CST)
-		*vr0min = vr1max;
-	      else if (TYPE_PRECISION (TREE_TYPE (vr1max)) == 1
-		       && !TYPE_UNSIGNED (TREE_TYPE (vr1max)))
-		*vr0min
-		  = int_const_binop (MINUS_EXPR, vr1max,
-				     build_int_cst (TREE_TYPE (vr1max), -1));
-	      else
-		*vr0min
-		  = int_const_binop (PLUS_EXPR, vr1max,
-				     build_int_cst (TREE_TYPE (vr1max), 1));
-	    }
-	  /* Choose the left gap if the right one is empty.  */
-	  else if (maxeq)
-	    {
-	      if (TREE_CODE (vr1min) != INTEGER_CST)
-		*vr0max = vr1min;
-	      else if (TYPE_PRECISION (TREE_TYPE (vr1min)) == 1
-		       && !TYPE_UNSIGNED (TREE_TYPE (vr1min)))
-		*vr0max
-		  = int_const_binop (PLUS_EXPR, vr1min,
-				     build_int_cst (TREE_TYPE (vr1min), -1));
-	      else
-		*vr0max
-		  = int_const_binop (MINUS_EXPR, vr1min,
-				     build_int_cst (TREE_TYPE (vr1min), 1));
-	    }
-	  /* Choose the anti-range if the range is effectively varying.  */
-	  else if (vrp_val_is_min (*vr0min)
-		   && vrp_val_is_max (*vr0max))
-	    {
-	      *vr0type = vr1type;
-	      *vr0min = vr1min;
-	      *vr0max = vr1max;
-	    }
-	  /* Else choose the range.  */
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	/* If both are anti-ranges the result is the outer one.  */
-	;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  /* The intersection is empty.  */
-	  *vr0type = VR_UNDEFINED;
-	  *vr0min = NULL_TREE;
-	  *vr0max = NULL_TREE;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if ((maxeq || operand_less_p (*vr0max, vr1max) == 1)
-	   && (mineq || operand_less_p (vr1min, *vr0min) == 1))
-    {
-      /* ( [  ] ) or ([  ] ) or ( [  ]) */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_RANGE)
-	/* Choose the inner range.  */
-	;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  /* Choose the right gap if the left is empty.  */
-	  if (mineq)
-	    {
-	      *vr0type = VR_RANGE;
-	      if (TREE_CODE (*vr0max) != INTEGER_CST)
-		*vr0min = *vr0max;
-	      else if (TYPE_PRECISION (TREE_TYPE (*vr0max)) == 1
-		       && !TYPE_UNSIGNED (TREE_TYPE (*vr0max)))
-		*vr0min
-		  = int_const_binop (MINUS_EXPR, *vr0max,
-				     build_int_cst (TREE_TYPE (*vr0max), -1));
-	      else
-		*vr0min
-		  = int_const_binop (PLUS_EXPR, *vr0max,
-				     build_int_cst (TREE_TYPE (*vr0max), 1));
-	      *vr0max = vr1max;
-	    }
-	  /* Choose the left gap if the right is empty.  */
-	  else if (maxeq)
-	    {
-	      *vr0type = VR_RANGE;
-	      if (TREE_CODE (*vr0min) != INTEGER_CST)
-		*vr0max = *vr0min;
-	      else if (TYPE_PRECISION (TREE_TYPE (*vr0min)) == 1
-		       && !TYPE_UNSIGNED (TREE_TYPE (*vr0min)))
-		*vr0max
-		  = int_const_binop (PLUS_EXPR, *vr0min,
-				     build_int_cst (TREE_TYPE (*vr0min), -1));
-	      else
-		*vr0max
-		  = int_const_binop (MINUS_EXPR, *vr0min,
-				     build_int_cst (TREE_TYPE (*vr0min), 1));
-	      *vr0min = vr1min;
-	    }
-	  /* Choose the anti-range if the range is effectively varying.  */
-	  else if (vrp_val_is_min (vr1min)
-		   && vrp_val_is_max (vr1max))
-	    ;
-	  /* Choose the anti-range if it is ~[0,0], that range is special
-	     enough to special case when vr1's range is relatively wide.
-	     At least for types bigger than int - this covers pointers
-	     and arguments to functions like ctz.  */
-	  else if (*vr0min == *vr0max
-		   && integer_zerop (*vr0min)
-		   && ((TYPE_PRECISION (TREE_TYPE (*vr0min))
-			>= TYPE_PRECISION (integer_type_node))
-		       || POINTER_TYPE_P (TREE_TYPE (*vr0min)))
-		   && TREE_CODE (vr1max) == INTEGER_CST
-		   && TREE_CODE (vr1min) == INTEGER_CST
-		   && (wi::clz (wi::to_wide (vr1max) - wi::to_wide (vr1min))
-		       < TYPE_PRECISION (TREE_TYPE (*vr0min)) / 2))
-	    ;
-	  /* Else choose the range.  */
-	  else
-	    {
-	      *vr0type = vr1type;
-	      *vr0min = vr1min;
-	      *vr0max = vr1max;
-	    }
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  /* If both are anti-ranges the result is the outer one.  */
-	  *vr0type = vr1type;
-	  *vr0min = vr1min;
-	  *vr0max = vr1max;
-	}
-      else if (vr1type == VR_ANTI_RANGE
-	       && *vr0type == VR_RANGE)
-	{
-	  /* The intersection is empty.  */
-	  *vr0type = VR_UNDEFINED;
-	  *vr0min = NULL_TREE;
-	  *vr0max = NULL_TREE;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if ((operand_less_p (vr1min, *vr0max) == 1
-	    || operand_equal_p (vr1min, *vr0max, 0))
-	   && operand_less_p (*vr0min, vr1min) == 1
-	   && operand_less_p (*vr0max, vr1max) == 1)
-    {
-      /* [  (  ]  ) or [  ](  ) */
-      if (*vr0type == VR_ANTI_RANGE
-	  && vr1type == VR_ANTI_RANGE)
-	*vr0max = vr1max;
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_RANGE)
-	*vr0min = vr1min;
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  if (TREE_CODE (vr1min) == INTEGER_CST)
-	    *vr0max = int_const_binop (MINUS_EXPR, vr1min,
-				       build_int_cst (TREE_TYPE (vr1min), 1));
-	  else
-	    *vr0max = vr1min;
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  *vr0type = VR_RANGE;
-	  if (TREE_CODE (*vr0max) == INTEGER_CST)
-	    *vr0min = int_const_binop (PLUS_EXPR, *vr0max,
-				       build_int_cst (TREE_TYPE (*vr0max), 1));
-	  else
-	    *vr0min = *vr0max;
-	  *vr0max = vr1max;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if ((operand_less_p (*vr0min, vr1max) == 1
-	    || operand_equal_p (*vr0min, vr1max, 0))
-	   && operand_less_p (vr1min, *vr0min) == 1
-	   && operand_less_p (vr1max, *vr0max) == 1)
-    {
-      /* (  [  )  ] or (  )[  ] */
-      if (*vr0type == VR_ANTI_RANGE
-	  && vr1type == VR_ANTI_RANGE)
-	*vr0min = vr1min;
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_RANGE)
-	*vr0max = vr1max;
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  if (TREE_CODE (vr1max) == INTEGER_CST)
-	    *vr0min = int_const_binop (PLUS_EXPR, vr1max,
-				       build_int_cst (TREE_TYPE (vr1max), 1));
-	  else
-	    *vr0min = vr1max;
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  *vr0type = VR_RANGE;
-	  if (TREE_CODE (*vr0min) == INTEGER_CST)
-	    *vr0max = int_const_binop (MINUS_EXPR, *vr0min,
-				       build_int_cst (TREE_TYPE (*vr0min), 1));
-	  else
-	    *vr0max = *vr0min;
-	  *vr0min = vr1min;
-	}
-      else
-	gcc_unreachable ();
-    }
-
-  /* If we know the intersection is empty, there's no need to
-     conservatively add anything else to the set.  */
-  if (*vr0type == VR_UNDEFINED)
-    return;
-
-  /* As a fallback simply use { *VRTYPE, *VR0MIN, *VR0MAX } as
-     result for the intersection.  That's always a conservative
-     correct estimate unless VR1 is a constant singleton range
-     in which case we choose that.  */
-  if (vr1type == VR_RANGE
-      && is_gimple_min_invariant (vr1min)
-      && vrp_operand_equal_p (vr1min, vr1max))
-    {
-      *vr0type = vr1type;
-      *vr0min = vr1min;
-      *vr0max = vr1max;
-    }
-}
-
-/* Helper for the intersection operation for value ranges.  Given two
-   ranges VR0 and VR1, set VR0 to the intersection of both ranges.
-   This may not be the smallest possible such range.  */
-
-void
-irange::legacy_intersect (irange *vr0, const irange *vr1)
-{
-  gcc_checking_assert (vr0->legacy_mode_p ());
-  gcc_checking_assert (vr1->legacy_mode_p ());
-  /* If either range is VR_VARYING the other one wins.  */
-  if (vr1->varying_p ())
-    return;
-  if (vr0->varying_p ())
-    {
-      vr0->set (vr1->min (), vr1->max (), vr1->kind ());
-      return;
-    }
-
-  /* When either range is VR_UNDEFINED the resulting range is
-     VR_UNDEFINED, too.  */
-  if (vr0->undefined_p ())
-    return;
-  if (vr1->undefined_p ())
-    {
-      vr0->set_undefined ();
-      return;
-    }
-
-  value_range_kind vr0kind = vr0->kind ();
-  tree vr0min = vr0->min ();
-  tree vr0max = vr0->max ();
-
-  intersect_ranges (&vr0kind, &vr0min, &vr0max,
-		    vr1->kind (), vr1->min (), vr1->max ());
-
-  /* Make sure to canonicalize the result though as the inversion of a
-     VR_RANGE can still be a VR_RANGE.  */
-  if (vr0kind == VR_UNDEFINED)
-    vr0->set_undefined ();
-  else if (vr0kind == VR_VARYING)
-    {
-      /* If we failed, use the original VR0.  */
-      return;
-    }
-  else
-    vr0->set (vr0min, vr0max, vr0kind);
-}
-
-/* Union the two value-ranges { *VR0TYPE, *VR0MIN, *VR0MAX } and
-   { VR1TYPE, VR0MIN, VR0MAX } and store the result
-   in { *VR0TYPE, *VR0MIN, *VR0MAX }.  This may not be the smallest
-   possible such range.  The resulting range is not canonicalized.  */
-
-static void
-union_ranges (enum value_range_kind *vr0type,
-	      tree *vr0min, tree *vr0max,
-	      enum value_range_kind vr1type,
-	      tree vr1min, tree vr1max)
-{
-  int cmpmin = compare_values (*vr0min, vr1min);
-  int cmpmax = compare_values (*vr0max, vr1max);
-  bool mineq = cmpmin == 0;
-  bool maxeq = cmpmax == 0;
-
-  /* [] is vr0, () is vr1 in the following classification comments.  */
-  if (mineq && maxeq)
-    {
-      /* [(  )] */
-      if (*vr0type == vr1type)
-	/* Nothing to do for equal ranges.  */
-	;
-      else if ((*vr0type == VR_RANGE
-		&& vr1type == VR_ANTI_RANGE)
-	       || (*vr0type == VR_ANTI_RANGE
-		   && vr1type == VR_RANGE))
-	{
-	  /* For anti-range with range union the result is varying.  */
-	  goto give_up;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if (operand_less_p (*vr0max, vr1min) == 1
-	   || operand_less_p (vr1max, *vr0min) == 1)
-    {
-      /* [ ] ( ) or ( ) [ ]
-	 If the ranges have an empty intersection, result of the union
-	 operation is the anti-range or if both are anti-ranges
-	 it covers all.  */
-      if (*vr0type == VR_ANTI_RANGE
-	  && vr1type == VR_ANTI_RANGE)
-	goto give_up;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	;
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  *vr0type = vr1type;
-	  *vr0min = vr1min;
-	  *vr0max = vr1max;
-	}
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  /* The result is the convex hull of both ranges.  */
-	  if (operand_less_p (*vr0max, vr1min) == 1)
-	    {
-	      /* If the result can be an anti-range, create one.  */
-	      if (TREE_CODE (*vr0max) == INTEGER_CST
-		  && TREE_CODE (vr1min) == INTEGER_CST
-		  && vrp_val_is_min (*vr0min)
-		  && vrp_val_is_max (vr1max))
-		{
-		  tree min = int_const_binop (PLUS_EXPR,
-					      *vr0max,
-					      build_int_cst (TREE_TYPE (*vr0max), 1));
-		  tree max = int_const_binop (MINUS_EXPR,
-					      vr1min,
-					      build_int_cst (TREE_TYPE (vr1min), 1));
-		  if (!operand_less_p (max, min))
-		    {
-		      *vr0type = VR_ANTI_RANGE;
-		      *vr0min = min;
-		      *vr0max = max;
-		    }
-		  else
-		    *vr0max = vr1max;
-		}
-	      else
-		*vr0max = vr1max;
-	    }
-	  else
-	    {
-	      /* If the result can be an anti-range, create one.  */
-	      if (TREE_CODE (vr1max) == INTEGER_CST
-		  && TREE_CODE (*vr0min) == INTEGER_CST
-		  && vrp_val_is_min (vr1min)
-		  && vrp_val_is_max (*vr0max))
-		{
-		  tree min = int_const_binop (PLUS_EXPR,
-					      vr1max,
-					      build_int_cst (TREE_TYPE (vr1max), 1));
-		  tree max = int_const_binop (MINUS_EXPR,
-					      *vr0min,
-					      build_int_cst (TREE_TYPE (*vr0min), 1));
-		  if (!operand_less_p (max, min))
-		    {
-		      *vr0type = VR_ANTI_RANGE;
-		      *vr0min = min;
-		      *vr0max = max;
-		    }
-		  else
-		    *vr0min = vr1min;
-		}
-	      else
-		*vr0min = vr1min;
-	    }
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if ((maxeq || cmpmax == 1)
-	   && (mineq || cmpmin == -1))
-    {
-      /* [ (  ) ] or [(  ) ] or [ (  )] */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_RANGE)
-	;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  *vr0type = vr1type;
-	  *vr0min = vr1min;
-	  *vr0max = vr1max;
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  /* Arbitrarily choose the right or left gap.  */
-	  if (!mineq && TREE_CODE (vr1min) == INTEGER_CST)
-	    *vr0max = int_const_binop (MINUS_EXPR, vr1min,
-				       build_int_cst (TREE_TYPE (vr1min), 1));
-	  else if (!maxeq && TREE_CODE (vr1max) == INTEGER_CST)
-	    *vr0min = int_const_binop (PLUS_EXPR, vr1max,
-				       build_int_cst (TREE_TYPE (vr1max), 1));
-	  else
-	    goto give_up;
-	}
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	/* The result covers everything.  */
-	goto give_up;
-      else
-	gcc_unreachable ();
-    }
-  else if ((maxeq || cmpmax == -1)
-	   && (mineq || cmpmin == 1))
-    {
-      /* ( [  ] ) or ([  ] ) or ( [  ]) */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_RANGE)
-	{
-	  *vr0type = vr1type;
-	  *vr0min = vr1min;
-	  *vr0max = vr1max;
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	;
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  *vr0type = VR_ANTI_RANGE;
-	  if (!mineq && TREE_CODE (*vr0min) == INTEGER_CST)
-	    {
-	      *vr0max = int_const_binop (MINUS_EXPR, *vr0min,
-					 build_int_cst (TREE_TYPE (*vr0min), 1));
-	      *vr0min = vr1min;
-	    }
-	  else if (!maxeq && TREE_CODE (*vr0max) == INTEGER_CST)
-	    {
-	      *vr0min = int_const_binop (PLUS_EXPR, *vr0max,
-					 build_int_cst (TREE_TYPE (*vr0max), 1));
-	      *vr0max = vr1max;
-	    }
-	  else
-	    goto give_up;
-	}
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	/* The result covers everything.  */
-	goto give_up;
-      else
-	gcc_unreachable ();
-    }
-  else if (cmpmin == -1
-	   && cmpmax == -1
-	   && (operand_less_p (vr1min, *vr0max) == 1
-	       || operand_equal_p (vr1min, *vr0max, 0)))
-    {
-      /* [  (  ]  ) or [   ](   ) */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_RANGE)
-	*vr0max = vr1max;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	*vr0min = vr1min;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  if (TREE_CODE (vr1min) == INTEGER_CST)
-	    *vr0max = int_const_binop (MINUS_EXPR, vr1min,
-				       build_int_cst (TREE_TYPE (vr1min), 1));
-	  else
-	    goto give_up;
-	}
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  if (TREE_CODE (*vr0max) == INTEGER_CST)
-	    {
-	      *vr0type = vr1type;
-	      *vr0min = int_const_binop (PLUS_EXPR, *vr0max,
-					 build_int_cst (TREE_TYPE (*vr0max), 1));
-	      *vr0max = vr1max;
-	    }
-	  else
-	    goto give_up;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else if (cmpmin == 1
-	   && cmpmax == 1
-	   && (operand_less_p (*vr0min, vr1max) == 1
-	       || operand_equal_p (*vr0min, vr1max, 0)))
-    {
-      /* (  [  )  ] or (   )[   ] */
-      if (*vr0type == VR_RANGE
-	  && vr1type == VR_RANGE)
-	*vr0min = vr1min;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	*vr0max = vr1max;
-      else if (*vr0type == VR_ANTI_RANGE
-	       && vr1type == VR_RANGE)
-	{
-	  if (TREE_CODE (vr1max) == INTEGER_CST)
-	    *vr0min = int_const_binop (PLUS_EXPR, vr1max,
-				       build_int_cst (TREE_TYPE (vr1max), 1));
-	  else
-	    goto give_up;
-	}
-      else if (*vr0type == VR_RANGE
-	       && vr1type == VR_ANTI_RANGE)
-	{
-	  if (TREE_CODE (*vr0min) == INTEGER_CST)
-	    {
-	      *vr0type = vr1type;
-	      *vr0max = int_const_binop (MINUS_EXPR, *vr0min,
-					 build_int_cst (TREE_TYPE (*vr0min), 1));
-	      *vr0min = vr1min;
-	    }
-	  else
-	    goto give_up;
-	}
-      else
-	gcc_unreachable ();
-    }
-  else
-    goto give_up;
-
-  return;
-
-give_up:
-  *vr0type = VR_VARYING;
-  *vr0min = NULL_TREE;
-  *vr0max = NULL_TREE;
-}
-
-/* Helper for meet operation for value ranges.  Given two ranges VR0
-   and VR1, set VR0 to the union of both ranges.  This may not be the
-   smallest possible such range.  */
-
-void
-irange::legacy_union (irange *vr0, const irange *vr1)
-{
-  gcc_checking_assert (vr0->legacy_mode_p ());
-  gcc_checking_assert (vr1->legacy_mode_p ());
-
-  /* VR0 has the resulting range if VR1 is undefined or VR0 is varying.  */
-  if (vr1->undefined_p ()
-      || vr0->varying_p ())
-    return;
-
-  /* VR1 has the resulting range if VR0 is undefined or VR1 is varying.  */
-  if (vr0->undefined_p ())
-    {
-      vr0->set (vr1->min (), vr1->max (), vr1->kind ());
-      return;
-    }
-
-  if (vr1->varying_p ())
-    {
-      vr0->set_varying (vr1->type ());
-      return;
-    }
-
-  value_range_kind vr0kind = vr0->kind ();
-  tree vr0min = vr0->min ();
-  tree vr0max = vr0->max ();
-
-  union_ranges (&vr0kind, &vr0min, &vr0max,
-		vr1->kind (), vr1->min (), vr1->max ());
-
-  if (vr0kind == VR_UNDEFINED)
-    vr0->set_undefined ();
-  else if (vr0kind == VR_VARYING)
-    {
-      /* Failed to find an efficient meet.  Before giving up and
-	 setting the result to VARYING, see if we can at least derive
-	 a non-zero range.  */
-      if (range_includes_zero_p (vr0) == 0
-	  && range_includes_zero_p (vr1) == 0)
-	vr0->set_nonzero (vr0->type ());
-      else
-	vr0->set_varying (vr0->type ());
-    }
-  else
-    vr0->set (vr0min, vr0max, vr0kind);
-}
-
-/* Meet operation for value ranges.  Given two value ranges VR0 and
-   VR1, store in VR0 a range that contains both VR0 and VR1.  This
-   may not be the smallest possible such range.
-   Return TRUE if the original value changes.  */
-
-bool
-irange::legacy_verbose_union_ (const irange *other)
-{
-  if (legacy_mode_p ())
-    {
-      if (!other->legacy_mode_p ())
-	{
-	  int_range<1> tmp = *other;
-	  legacy_union (this, &tmp);
-	  return true;
-	}
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	{
-	  fprintf (dump_file, "Meeting\n  ");
-	  dump_value_range (dump_file, this);
-	  fprintf (dump_file, "\nand\n  ");
-	  dump_value_range (dump_file, other);
-	  fprintf (dump_file, "\n");
-	}
-
-      legacy_union (this, other);
-
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	{
-	  fprintf (dump_file, "to\n  ");
-	  dump_value_range (dump_file, this);
-	  fprintf (dump_file, "\n");
-	}
-      return true;
-    }
-
-  if (other->legacy_mode_p ())
-    {
-      int_range<2> wider = *other;
-      return irange_union (wider);
-    }
-  else
-    return irange_union (*other);
-}
-
-bool
-irange::legacy_verbose_intersect (const irange *other)
-{
-  if (legacy_mode_p ())
-    {
-      if (!other->legacy_mode_p ())
-	{
-	  int_range<1> tmp = *other;
-	  legacy_intersect (this, &tmp);
-	  return true;
-	}
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	{
-	  fprintf (dump_file, "Intersecting\n  ");
-	  dump_value_range (dump_file, this);
-	  fprintf (dump_file, "\nand\n  ");
-	  dump_value_range (dump_file, other);
-	  fprintf (dump_file, "\n");
-	}
-
-      legacy_intersect (this, other);
-
-      if (dump_file && (dump_flags & TDF_DETAILS))
-	{
-	  fprintf (dump_file, "to\n  ");
-	  dump_value_range (dump_file, this);
-	  fprintf (dump_file, "\n");
-	}
-      return true;
-    }
-
-  if (other->legacy_mode_p ())
-    {
-      int_range<2> wider;
-      wider = *other;
-      return irange_intersect (wider);
-    }
-  else
-    return irange_intersect (*other);
-}
-
 // Perform an efficient union with R when both ranges have only a single pair.
 // Excluded are VARYING and UNDEFINED ranges.
 
@@ -2314,8 +1297,6 @@ irange::irange_single_pair_union (const irange &r)
 bool
 irange::irange_union (const irange &r)
 {
-  gcc_checking_assert (!legacy_mode_p () && !r.legacy_mode_p ());
-
   if (r.undefined_p ())
     return false;
 
@@ -2485,7 +1466,6 @@ irange::irange_contains_p (const irange &r) const
 bool
 irange::irange_intersect (const irange &r)
 {
-  gcc_checking_assert (!legacy_mode_p () && !r.legacy_mode_p ());
   gcc_checking_assert (undefined_p () || r.undefined_p ()
 		       || range_compatible_p (type (), r.type ()));
 
@@ -2609,12 +1589,6 @@ irange::intersect (const wide_int& lb, const wide_int& ub)
   if (undefined_p ())
     return false;
 
-  if (legacy_mode_p ())
-    {
-      intersect (int_range<1> (type (), lb, ub));
-      return true;
-    }
-
   tree range_type = type();
   signop sign = TYPE_SIGN (range_type);
 
@@ -2701,19 +1675,6 @@ add_one (const wide_int &x, tree type, wi::overflow_type &overflow)
 void
 irange::invert ()
 {
-  if (legacy_mode_p ())
-    {
-      // We can't just invert VR_RANGE and VR_ANTI_RANGE because we may
-      // create non-canonical ranges.  Use the constructors instead.
-      if (m_kind == VR_RANGE)
-	*this = value_range (min (), max (), VR_ANTI_RANGE);
-      else if (m_kind == VR_ANTI_RANGE)
-	*this = value_range (min (), max ());
-      else
-	gcc_unreachable ();
-      return;
-    }
-
   gcc_checking_assert (!undefined_p () && !varying_p ());
 
   // We always need one more set of bounds to represent an inverse, so
@@ -3029,47 +1990,6 @@ debug (const value_range &vr)
   fprintf (stderr, "\n");
 }
 
-/* Create two value-ranges in *VR0 and *VR1 from the anti-range *AR
-   so that *VR0 U *VR1 == *AR.  Returns true if that is possible,
-   false otherwise.  If *AR can be represented with a single range
-   *VR1 will be VR_UNDEFINED.  */
-
-bool
-ranges_from_anti_range (const value_range *ar,
-			value_range *vr0, value_range *vr1)
-{
-  tree type = ar->type ();
-
-  vr0->set_undefined ();
-  vr1->set_undefined ();
-
-  /* As a future improvement, we could handle ~[0, A] as: [-INF, -1] U
-     [A+1, +INF].  Not sure if this helps in practice, though.  */
-
-  tree ar_min, ar_max;
-  value_range_kind kind = get_legacy_range (*ar, ar_min, ar_max);
-  if (kind != VR_ANTI_RANGE
-      || TREE_CODE (ar_min) != INTEGER_CST
-      || TREE_CODE (ar_max) != INTEGER_CST
-      || !vrp_val_min (type)
-      || !vrp_val_max (type))
-    return false;
-
-  if (tree_int_cst_lt (vrp_val_min (type), ar_min))
-    vr0->set (vrp_val_min (type),
-	      wide_int_to_tree (type, wi::to_wide (ar_min) - 1));
-  if (tree_int_cst_lt (ar_max, vrp_val_max (type)))
-    vr1->set (wide_int_to_tree (type, wi::to_wide (ar_max) + 1),
-	      vrp_val_max (type));
-  if (vr0->undefined_p ())
-    {
-      *vr0 = *vr1;
-      vr1->set_undefined ();
-    }
-
-  return !vr0->undefined_p ();
-}
-
 /* Return whether VAL is equal to the maximum value of its type.
    We can't do a simple equality comparison with TYPE_MAX_VALUE because
    C typedefs and Ada subtypes can produce types whose TYPE_MAX_VALUE
@@ -3196,13 +2116,13 @@ gt_pch_nx (vrange *x, gt_pointer_operator op, void *cookie)
 // hash_traits.  hash-traits.h defines an extern of gt_ggc_mx (T &)
 // instead of picking up the gt_ggc_mx (T *) version.
 void
-gt_pch_nx (int_range<1> *&x)
+gt_pch_nx (int_range<2> *&x)
 {
   return gt_pch_nx ((irange *) x);
 }
 
 void
-gt_ggc_mx (int_range<1> *&x)
+gt_ggc_mx (int_range<2> *&x)
 {
   return gt_ggc_mx ((irange *) x);
 }
@@ -3359,37 +2279,6 @@ range_tests_int_range_max ()
   }
 }
 
-static void
-range_tests_legacy ()
-{
-  // Test truncating copy to int_range<1>.
-  int_range<3> big = build_range3 (10, 20, 30, 40, 50, 60);
-  int_range<1> small = big;
-  ASSERT_TRUE (small == int_range<1> (INT (10), INT (60)));
-
-  // Test truncating copy to int_range<2>.
-  int_range<2> medium = big;
-  ASSERT_TRUE (!medium.undefined_p ());
-
-  // Test that a truncating copy of [MIN,20][22,40][80,MAX]
-  // ends up as a conservative anti-range of ~[21,21].
-  big = int_range<3> (vrp_val_min (integer_type_node), INT (20));
-  big.union_ (int_range<1> (INT (22), INT (40)));
-  big.union_ (int_range<1> (INT (80), vrp_val_max (integer_type_node)));
-  small = big;
-  ASSERT_TRUE (small == int_range<1> (INT (21), INT (21), VR_ANTI_RANGE));
-
-  // VARYING of different sizes should not be equal.
-  tree big_type = build_nonstandard_integer_type (32, 1);
-  tree small_type = build_nonstandard_integer_type (16, 1);
-  int_range_max r0 (big_type);
-  int_range_max r1 (small_type);
-  ASSERT_TRUE (r0 != r1);
-  value_range vr0 (big_type);
-  int_range_max vr1 (small_type);
-  ASSERT_TRUE (vr0 != vr1);
-}
-
 // Simulate -fstrict-enums where the domain of a type is less than the
 // underlying type.
 
@@ -3426,8 +2315,8 @@ static void
 range_tests_misc ()
 {
   tree u128_type = build_nonstandard_integer_type (128, /*unsigned=*/1);
-  int_range<1> i1, i2, i3;
-  int_range<1> r0, r1, rold;
+  int_range<2> i1, i2, i3;
+  int_range<2> r0, r1, rold;
 
   // Test 1-bit signed integer union.
   // [-1,-1] U [0,0] = VARYING.
@@ -3461,7 +2350,7 @@ range_tests_misc ()
   ASSERT_TRUE (not_255 == int_range<1> (UCHAR (0), UCHAR (254)));
 
   // Test that NOT(0) is [1..255] in 8-bit land.
-  int_range<1> not_zero = range_nonzero (unsigned_char_type_node);
+  int_range<2> not_zero = range_nonzero (unsigned_char_type_node);
   ASSERT_TRUE (not_zero == int_range<1> (UCHAR (1), UCHAR (255)));
 
   // Check that [0,127][0x..ffffff80,0x..ffffff]
@@ -3506,14 +2395,14 @@ range_tests_misc ()
   ASSERT_TRUE (r0 == r1);
 
   // Check that [~5] is really [-MIN,4][6,MAX].
-  r0 = int_range<1> (INT (5), INT (5), VR_ANTI_RANGE);
+  r0 = int_range<2> (INT (5), INT (5), VR_ANTI_RANGE);
   r1 = int_range<1> (minint, INT (4));
   r1.union_ (int_range<1> (INT (6), maxint));
   ASSERT_FALSE (r1.undefined_p ());
   ASSERT_TRUE (r0 == r1);
 
   r1 = int_range<1> (INT (5), INT (5));
-  int_range<1> r2 (r1);
+  int_range<2> r2 (r1);
   ASSERT_TRUE (r1 == r2);
 
   r1 = int_range<1> (INT (5), INT (10));
@@ -3598,11 +2487,10 @@ range_tests_misc ()
   r0.invert ();
   ASSERT_TRUE (r0.nonzero_p ());
 
-  // test legacy interaction
   // r0 = ~[1,1]
-  r0 = int_range<1> (UINT (1), UINT (1), VR_ANTI_RANGE);
+  r0 = int_range<2> (UINT (1), UINT (1), VR_ANTI_RANGE);
   // r1 = ~[3,3]
-  r1 = int_range<1> (UINT (3), UINT (3), VR_ANTI_RANGE);
+  r1 = int_range<2> (UINT (3), UINT (3), VR_ANTI_RANGE);
 
   // vv = [0,0][2,2][4, MAX]
   int_range<3> vv = r0;
@@ -3611,7 +2499,6 @@ range_tests_misc ()
   ASSERT_TRUE (vv.contains_p (UINT (2)));
   ASSERT_TRUE (vv.num_pairs () == 3);
 
-  // create r0 as legacy [1,1]
   r0 = int_range<1> (UINT (1), UINT (1));
   // And union it with  [0,0][2,2][4,MAX] multi range
   r0.union_ (vv);
@@ -4069,7 +2956,6 @@ range_tests_floats_various ()
 void
 range_tests ()
 {
-  range_tests_legacy ();
   range_tests_irange3 ();
   range_tests_int_range_max ();
   range_tests_strict_enum ();
diff --git a/gcc/value-range.h b/gcc/value-range.h
index b47540d49be..c37b6ef9984 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -120,7 +120,6 @@ class GTY((user)) irange : public vrange
 {
   friend value_range_kind get_legacy_range (const irange &, tree &, tree &);
   friend class vrange_allocator;
-  friend class irange_storage_slot; // For legacy_mode_p checks.
 public:
   // In-place setters.
   virtual void set (tree, tree, value_range_kind = VR_RANGE) override;
@@ -170,8 +169,6 @@ public:
   // Deprecated legacy public methods.
   tree min () const;				// DEPRECATED
   tree max () const;				// DEPRECATED
-  bool legacy_verbose_union_ (const class irange *);	// DEPRECATED
-  bool legacy_verbose_intersect (const irange *);	// DEPRECATED
 
 protected:
   irange (tree *, unsigned);
@@ -190,16 +187,8 @@ protected:
 
   void normalize_kind ();
 
-  bool legacy_mode_p () const;
-  bool legacy_equal_p (const irange &) const;
-  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;
   int value_inside_range (tree) const;
-  void copy_to_legacy (const irange &);
-  void copy_legacy_to_multi_range (const irange &);
 
 private:
   friend void gt_ggc_mx (irange *);
@@ -242,12 +231,6 @@ private:
   template <unsigned X> friend void gt_pch_nx (int_range<X> *,
 					       gt_pointer_operator, void *);
 
-  // ?? These stubs are for ipa-prop.cc which use a value_range in a
-  // hash_traits.  hash-traits.h defines an extern of gt_ggc_mx (T &)
-  // instead of picking up the gt_ggc_mx (T *) version.
-  friend void gt_ggc_mx (int_range<1> *&);
-  friend void gt_pch_nx (int_range<1> *&);
-
   tree m_ranges[N*2];
 };
 
@@ -485,15 +468,7 @@ public:
   virtual void visit (const unsupported_range &) const { }
 };
 
-// This is a special int_range<1> with only one pair, plus
-// VR_ANTI_RANGE magic to describe slightly more than can be described
-// in one pair.  It is described in the code as a "legacy range" (as
-// opposed to multi-ranges which have multiple sub-ranges).  It is
-// provided for backward compatibility with code that has not been
-// converted to multi-range irange's.
-//
-// There are copy operators to seamlessly copy to/fro multi-ranges.
-typedef int_range<1> value_range;
+typedef int_range<2> value_range;
 
 // This is an "infinite" precision irange for use in temporary
 // calculations.
@@ -662,15 +637,6 @@ Value_Range::supports_type_p (const_tree type)
   return irange::supports_p (type) || frange::supports_p (type);
 }
 
-// Returns true for an old-school value_range as described above.
-inline bool
-irange::legacy_mode_p () const
-{
-  return m_max_ranges == 1;
-}
-
-extern bool ranges_from_anti_range (const value_range *,
-				    value_range *, value_range *);
 extern value_range_kind get_legacy_range (const irange &, tree &min, tree &max);
 extern void dump_value_range (FILE *, const vrange *);
 extern bool vrp_val_is_min (const_tree);
@@ -810,7 +776,7 @@ irange::nonzero_p () const
     return false;
 
   tree zero = build_zero_cst (type ());
-  return *this == int_range<1> (zero, zero, VR_ANTI_RANGE);
+  return *this == int_range<2> (zero, zero, VR_ANTI_RANGE);
 }
 
 inline bool
@@ -977,8 +943,6 @@ 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 ());
   return wi::to_wide (tree_lower_bound (pair));
@@ -990,8 +954,6 @@ 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 ());
   return wi::to_wide (tree_upper_bound (pair));
@@ -1010,21 +972,13 @@ irange::upper_bound () const
 inline bool
 irange::union_ (const vrange &r)
 {
-  dump_flags_t m_flags = dump_flags;
-  dump_flags &= ~TDF_DETAILS;
-  bool ret = irange::legacy_verbose_union_ (&as_a <irange> (r));
-  dump_flags = m_flags;
-  return ret;
+  return irange_union (as_a <irange> (r));
 }
 
 inline bool
 irange::intersect (const vrange &r)
 {
-  dump_flags_t m_flags = dump_flags;
-  dump_flags &= ~TDF_DETAILS;
-  bool ret = irange::legacy_verbose_intersect (&as_a <irange> (r));
-  dump_flags = m_flags;
-  return ret;
+  return irange_intersect (as_a <irange> (r));
 }
 
 // Set value range VR to a nonzero range of type TYPE.
@@ -1033,10 +987,7 @@ inline void
 irange::set_nonzero (tree type)
 {
   tree zero = build_int_cst (type, 0);
-  if (legacy_mode_p ())
-    set (zero, zero, VR_ANTI_RANGE);
-  else
-    irange_set_anti_range (zero, zero);
+  irange_set_anti_range (zero, zero);
 }
 
 // Set value range VR to a ZERO range of type TYPE.
@@ -1045,10 +996,7 @@ inline void
 irange::set_zero (tree type)
 {
   tree z = build_int_cst (type, 0);
-  if (legacy_mode_p ())
-    set (z, z);
-  else
-    irange_set (z, z);
+  irange_set (z, z);
 }
 
 // Normalize a range to VARYING or UNDEFINED if possible.
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index ea7c6738739..2ee234c4d88 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -751,10 +751,10 @@ simplify_using_ranges::legacy_fold_cond_overflow (gimple *stmt,
 	     for previously LE_ or LT_EXPR and GT_EXPR otherwise, but
 	     the comments next to the enclosing if suggest it's not
 	     generally profitable to do so.  */
-	  vro.legacy_verbose_intersect (&vr0);
+	  vro.intersect (vr0);
 	  if (vro.undefined_p ())
 	    return boolean_false_node;
-	  vri.legacy_verbose_intersect (&vr0);
+	  vri.intersect (vr0);
 	  if (vri.undefined_p ())
 	    return boolean_true_node;
 	}
-- 
2.40.0


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

end of thread, other threads:[~2023-04-26 11:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-26 11:47 [COMMITTED] Fix swapping of ranges Aldy Hernandez
2023-04-26 11:47 ` [COMMITTED] Replace ad-hoc value_range dumpers with irange::dump Aldy Hernandez
2023-04-26 11:47 ` [COMMITTED] Remove some uses of deprecated irange API Aldy Hernandez
2023-04-26 11:47 ` [COMMITTED] Convert compare_nonzero_chars to wide_ints Aldy Hernandez
2023-04-26 11:47 ` [COMMITTED] Remove range_int_cst_p Aldy Hernandez
2023-04-26 11:47 ` [COMMITTED] Remove range_has_numeric_bounds_p Aldy Hernandez
2023-04-26 11:47 ` [COMMITTED] Remove legacy range support 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).