diff mbox series

[COMMITTED] Remove range_int_cst_p.

Message ID 20230426114752.336928-5-aldyh@redhat.com
State New
Headers show
Series [COMMITTED] Remove range_int_cst_p. | expand

Commit Message

Aldy Hernandez April 26, 2023, 11:47 a.m. UTC
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 mbox series

Patch

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.  */