public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Make irange::intersect(wide_int, wide_int) private.
@ 2022-04-29  9:02 Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Call set_undefined from irange constructor Aldy Hernandez
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-04-29  9:02 UTC (permalink / raw)
  To: GCC patches

[I will be committing a series of small, hopefully non-intrusive
cleanups to trunk in preparation for work to be done later this cycle
that will definitely be invasive ;-).  If these changes turn out to be
remotely problematic, I can revert them, but I'm trying to get them in
early because I'm leaving on a 6 week paternity leave on May 9th and
would prefer the wider testing before departing.]

This method should have been private, and somehow seeped into the API.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

	* gimple-range-cache.h (non_null_ref::adjust_range): Do not use
	irange::intersect (wide_int, wide_int).
	* gimple-range-fold.cc (adjust_pointer_diff_expr): Same.
	(adjust_imagpart_expr): Same.
	* value-range.h (irange::intersect (wide_int, wide_int)): Make
	private.
---
 gcc/gimple-range-cache.h | 6 ++++--
 gcc/gimple-range-fold.cc | 6 +++---
 gcc/value-range.h        | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h
index 589b649da26..a0244e4f6a4 100644
--- a/gcc/gimple-range-cache.h
+++ b/gcc/gimple-range-cache.h
@@ -64,8 +64,10 @@ non_null_ref::adjust_range (irange &r, tree name, basic_block bb,
   if (non_null_deref_p (name, bb, search_dom))
     {
       // Remove zero from the range.
-      unsigned prec = TYPE_PRECISION (TREE_TYPE (name));
-      r.intersect (wi::one (prec), wi::max_value (prec, UNSIGNED));
+      gcc_checking_assert (TYPE_UNSIGNED (TREE_TYPE (name)));
+      int_range<2> nz;
+      nz.set_nonzero (TREE_TYPE (name));
+      r.intersect (nz);
       return true;
     }
   return false;
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index dfacf6f14dc..3169e29b5de 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -362,7 +362,7 @@ adjust_pointer_diff_expr (irange &res, const gimple *diff_stmt)
       tree max = vrp_val_max (ptrdiff_type_node);
       unsigned prec = TYPE_PRECISION (TREE_TYPE (max));
       wide_int wmaxm1 = wi::to_wide (max, prec) - 1;
-      res.intersect (wi::zero (prec), wmaxm1);
+      res.intersect (int_range<2> (TREE_TYPE (max), wi::zero (prec), wmaxm1));
     }
 }
 
@@ -403,8 +403,8 @@ adjust_imagpart_expr (irange &res, const gimple *stmt)
       tree cst = gimple_assign_rhs1 (def_stmt);
       if (TREE_CODE (cst) == COMPLEX_CST)
 	{
-	  wide_int imag = wi::to_wide (TREE_IMAGPART (cst));
-	  res.intersect (imag, imag);
+	  int_range<2> imag (TREE_IMAGPART (cst), TREE_IMAGPART (cst));
+	  res.intersect (imag);
 	}
     }
 }
diff --git a/gcc/value-range.h b/gcc/value-range.h
index d4cba22d540..fe7795b55a6 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -73,7 +73,6 @@ public:
   // In-place operators.
   void union_ (const irange &);
   void intersect (const irange &);
-  void intersect (const wide_int& lb, const wide_int& ub);
   void invert ();
 
   // Operator overloads.
@@ -135,6 +134,7 @@ private:
   void irange_set_1bit_anti_range (tree, tree);
   bool varying_compatible_p () const;
 
+  void intersect (const wide_int& lb, const wide_int& ub);
   unsigned char m_num_ranges;
   unsigned char m_max_ranges;
   ENUM_BITFIELD(value_range_kind) m_kind : 8;
-- 
2.35.1


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

* [COMMITTED] Call set_undefined from irange constructor.
  2022-04-29  9:02 [COMMITTED] Make irange::intersect(wide_int, wide_int) private Aldy Hernandez
@ 2022-04-29  9:02 ` Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Prefer global range info setters that take a range Aldy Hernandez
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-04-29  9:02 UTC (permalink / raw)
  To: GCC patches

Small clean up to use set_undefined instead of duplicating the
functionality therein.

Tested on x86-64 Linux.

gcc/ChangeLog:

	* value-range.h (irange::irange): Use set_undefined.
---
 gcc/value-range.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/value-range.h b/gcc/value-range.h
index fe7795b55a6..b64e02426ca 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -397,9 +397,8 @@ inline
 irange::irange (tree *base, unsigned nranges)
 {
   m_base = base;
-  m_num_ranges = 0;
   m_max_ranges = nranges;
-  m_kind = VR_UNDEFINED;
+  set_undefined ();
 }
 
 // Constructors for int_range<>.
-- 
2.35.1


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

* [COMMITTED] Prefer global range info setters that take a range.
  2022-04-29  9:02 [COMMITTED] Make irange::intersect(wide_int, wide_int) private Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Call set_undefined from irange constructor Aldy Hernandez
@ 2022-04-29  9:02 ` Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Remove various deprecated methods in class irange Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Move common code from range-op.cc to header files Aldy Hernandez
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-04-29  9:02 UTC (permalink / raw)
  To: GCC patches

This patch consolidates the multiple ways we have of storing global
ranges into one accepting a range.

In an upcoming patch series later this cycle we will be providing a
way to store iranges globally, as opposed to the mechanism we have now
which squishes wider ranges into value_range's.  This is preparation
for such work.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

	* gimple-ssa-evrp-analyze.cc
	(evrp_range_analyzer::set_ssa_range_info): Use *range_info methods
	that take a range.
	* gimple-ssa-sprintf.cc (try_substitute_return_value): Same.
	* ipa-prop.cc (ipcp_update_vr): Same.
	* tree-inline.cc (remap_ssa_name): Same.
	* tree-ssa-copy.cc (fini_copy_prop): Same.
	* tree-ssa-math-opts.cc (optimize_spaceship): Same.
	* tree-ssa-phiopt.cc (replace_phi_edge_with_variable): Same.
	* tree-ssa-pre.cc (insert_into_preds_of_block): Same.
	* tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_stmt): Same.
	* tree-ssa-strlen.cc (set_strlen_range): Same.
	(strlen_pass::handle_builtin_string_cmp): Same.
	* tree-ssanames.cc (set_range_info): Make static.
	(duplicate_ssa_name_range_info): Make static and add a new variant
	calling the static.
	* tree-ssanames.h (set_range_info): Remove version taking wide ints.
	(duplicate_ssa_name_range_info): Remove version taking a
	range_info_def and replace with a version taking SSA names.
	* tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Use *range_info methods
	that take a range.
	(vect_do_peeling): Same.
	* tree-vrp.cc (vrp_asserts::remove_range_assertions): Same.
	* vr-values.cc (simplify_truth_ops_using_ranges): Same.
---
 gcc/gimple-ssa-evrp-analyze.cc |  4 +---
 gcc/gimple-ssa-sprintf.cc      |  3 ++-
 gcc/ipa-prop.cc                | 12 +++++-----
 gcc/tree-inline.cc             |  6 ++---
 gcc/tree-ssa-copy.cc           |  4 +---
 gcc/tree-ssa-math-opts.cc      |  3 ++-
 gcc/tree-ssa-phiopt.cc         |  4 +---
 gcc/tree-ssa-pre.cc            | 13 +++++------
 gcc/tree-ssa-sccvn.cc          |  4 +---
 gcc/tree-ssa-strlen.cc         |  8 ++++---
 gcc/tree-ssanames.cc           | 12 ++++++++--
 gcc/tree-ssanames.h            |  5 +----
 gcc/tree-vect-loop-manip.cc    | 41 +++++++++++++++++++++-------------
 gcc/tree-vrp.cc                | 13 ++++++++---
 gcc/vr-values.cc               |  9 +++++---
 15 files changed, 79 insertions(+), 62 deletions(-)

diff --git a/gcc/gimple-ssa-evrp-analyze.cc b/gcc/gimple-ssa-evrp-analyze.cc
index bed6dc2a70e..5b6c9f8fe1b 100644
--- a/gcc/gimple-ssa-evrp-analyze.cc
+++ b/gcc/gimple-ssa-evrp-analyze.cc
@@ -110,9 +110,7 @@ evrp_range_analyzer::set_ssa_range_info (tree lhs, value_range_equiv *vr)
   if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))
     {
       if (!vr->varying_p () && vr->constant_p ())
-	set_range_info (lhs, vr->kind (),
-			wi::to_wide (vr->min ()),
-			wi::to_wide (vr->max ()));
+	set_range_info (lhs, *vr);
     }
   else if (POINTER_TYPE_P (TREE_TYPE (lhs))
 	   && range_includes_zero_p (vr) == 0)
diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc
index c93f12f90b5..9a84fffed1a 100644
--- a/gcc/gimple-ssa-sprintf.cc
+++ b/gcc/gimple-ssa-sprintf.cc
@@ -4231,7 +4231,8 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
 
 	  wide_int min = wi::shwi (retval[0], prec);
 	  wide_int max = wi::shwi (retval[1], prec);
-	  set_range_info (lhs, VR_RANGE, min, max);
+	  value_range r (TREE_TYPE (lhs), min, max);
+	  set_range_info (lhs, r);
 
 	  setrange = true;
 	}
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 0e5966332eb..80e67e93e12 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -5987,11 +5987,13 @@ ipcp_update_vr (struct cgraph_node *node)
 		  print_decs (vr[i].max, dump_file);
 		  fprintf (dump_file, "]\n");
 		}
-	      set_range_info (ddef, vr[i].type,
-			      wide_int_storage::from (vr[i].min, prec,
-						      TYPE_SIGN (type)),
-			      wide_int_storage::from (vr[i].max, prec,
-						      TYPE_SIGN (type)));
+	      value_range v (type,
+			     wide_int_storage::from (vr[i].min, prec,
+						     TYPE_SIGN (type)),
+			     wide_int_storage::from (vr[i].max, prec,
+						     TYPE_SIGN (type)),
+			     vr[i].type);
+	      set_range_info (ddef, v);
 	    }
 	  else if (POINTER_TYPE_P (TREE_TYPE (ddef))
 		   && vr[i].nonzero_p (TREE_TYPE (ddef)))
diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc
index ca66a8266b1..29bb758b7bc 100644
--- a/gcc/tree-inline.cc
+++ b/gcc/tree-inline.cc
@@ -253,8 +253,7 @@ remap_ssa_name (tree name, copy_body_data *id)
       /* So can range-info.  */
       if (!POINTER_TYPE_P (TREE_TYPE (name))
 	  && SSA_NAME_RANGE_INFO (name))
-	duplicate_ssa_name_range_info (new_tree, SSA_NAME_RANGE_TYPE (name),
-				       SSA_NAME_RANGE_INFO (name));
+	duplicate_ssa_name_range_info (new_tree, name);
       return new_tree;
     }
 
@@ -291,8 +290,7 @@ remap_ssa_name (tree name, copy_body_data *id)
       /* So can range-info.  */
       if (!POINTER_TYPE_P (TREE_TYPE (name))
 	  && SSA_NAME_RANGE_INFO (name))
-	duplicate_ssa_name_range_info (new_tree, SSA_NAME_RANGE_TYPE (name),
-				       SSA_NAME_RANGE_INFO (name));
+	duplicate_ssa_name_range_info (new_tree, name);
       if (SSA_NAME_IS_DEFAULT_DEF (name))
 	{
 	  /* By inlining function having uninitialized variable, we might
diff --git a/gcc/tree-ssa-copy.cc b/gcc/tree-ssa-copy.cc
index 76513527a11..7d636ecd438 100644
--- a/gcc/tree-ssa-copy.cc
+++ b/gcc/tree-ssa-copy.cc
@@ -556,9 +556,7 @@ fini_copy_prop (void)
 		   && SSA_NAME_RANGE_INFO (var)
 		   && !SSA_NAME_RANGE_INFO (copy_of[i].value)
 		   && var_bb == copy_of_bb)
-	    duplicate_ssa_name_range_info (copy_of[i].value,
-					   SSA_NAME_RANGE_TYPE (var),
-					   SSA_NAME_RANGE_INFO (var));
+	    duplicate_ssa_name_range_info (copy_of[i].value, var);
 	}
     }
 
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index 7555793948e..b528b0523ff 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -4862,7 +4862,8 @@ optimize_spaceship (gimple *stmt)
 
   wide_int wm1 = wi::minus_one (TYPE_PRECISION (integer_type_node));
   wide_int w2 = wi::two (TYPE_PRECISION (integer_type_node));
-  set_range_info (lhs, VR_RANGE, wm1, w2);
+  value_range vr (TREE_TYPE (lhs), wm1, w2);
+  set_range_info (lhs, vr);
 }
 
 
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 3eda825672c..8c9c46d41f1 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -416,9 +416,7 @@ replace_phi_edge_with_variable (basic_block cond_block,
       && SSA_NAME_RANGE_INFO (phi_result)
       && gimple_bb (SSA_NAME_DEF_STMT (new_tree)) == cond_block
       && dbg_cnt (phiopt_edge_range))
-    duplicate_ssa_name_range_info (new_tree,
-				   SSA_NAME_RANGE_TYPE (phi_result),
-				   SSA_NAME_RANGE_INFO (phi_result));
+    duplicate_ssa_name_range_info (new_tree, phi_result);
 
   /* Change the PHI argument to new.  */
   SET_USE (PHI_ARG_DEF_PTR (phi, e->dest_idx), new_tree);
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index 47d70c85c3c..a578ce6dfa4 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -3246,14 +3246,11 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
 	  && r.kind () == VR_RANGE
 	  && !wi::neg_p (r.lower_bound (), SIGNED)
 	  && !wi::neg_p (r.upper_bound (), SIGNED))
-	/* Just handle extension and sign-changes of all-positive ranges.  */
-	set_range_info (temp, VR_RANGE,
-			wide_int_storage::from (r.lower_bound (),
-						TYPE_PRECISION (type),
-						TYPE_SIGN (type)),
-			wide_int_storage::from (r.upper_bound (),
-						TYPE_PRECISION (type),
-						TYPE_SIGN (type)));
+	{
+	  /* Just handle extension and sign-changes of all-positive ranges.  */
+	  range_cast (r, type);
+	  set_range_info (temp, r);
+	}
     }
 
   if (dump_file && (dump_flags & TDF_DETAILS))
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index d4d0aba880c..3c90c1e23e6 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -6304,9 +6304,7 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
 		   && SSA_NAME_RANGE_INFO (lhs)
 		   && ! SSA_NAME_RANGE_INFO (sprime)
 		   && b == sprime_b)
-	    duplicate_ssa_name_range_info (sprime,
-					   SSA_NAME_RANGE_TYPE (lhs),
-					   SSA_NAME_RANGE_INFO (lhs));
+	    duplicate_ssa_name_range_info (sprime, lhs);
 	}
 
       /* Inhibit the use of an inserted PHI on a loop header when
diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc
index 9ae25d1dde2..1e5f911fedb 100644
--- a/gcc/tree-ssa-strlen.cc
+++ b/gcc/tree-ssa-strlen.cc
@@ -1951,7 +1951,8 @@ set_strlen_range (tree lhs, wide_int min, wide_int max,
   if (min == max)
     return wide_int_to_tree (size_type_node, min);
 
-  set_range_info (lhs, VR_RANGE, min, max);
+  value_range vr (TREE_TYPE (lhs), min, max);
+  set_range_info (lhs, vr);
   return lhs;
 }
 
@@ -4343,8 +4344,9 @@ strlen_pass::handle_builtin_string_cmp ()
 	       known to be unequal set the range of the result to non-zero.
 	       This allows the call to be eliminated if its result is only
 	       used in tests for equality to zero.  */
-	    wide_int zero = wi::zero (TYPE_PRECISION (TREE_TYPE (lhs)));
-	    set_range_info (lhs, VR_ANTI_RANGE, zero, zero);
+	    value_range nz;
+	    nz.set_nonzero (TREE_TYPE (lhs));
+	    set_range_info (lhs, nz);
 	    return false;
 	  }
 	/* When the two strings are definitely equal (such as when they
diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index e0a6884f295..c957597af4f 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -389,7 +389,7 @@ set_range_info_raw (tree name, enum value_range_kind range_type,
 /* Store range information RANGE_TYPE, MIN, and MAX to tree ssa_name
    NAME while making sure we don't store useless range info.  */
 
-void
+static void
 set_range_info (tree name, enum value_range_kind range_type,
 		const wide_int_ref &min, const wide_int_ref &max)
 {
@@ -720,7 +720,7 @@ duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info)
 
 /* Creates a duplicate of the range_info_def at RANGE_INFO of type
    RANGE_TYPE for use by the SSA name NAME.  */
-void
+static void
 duplicate_ssa_name_range_info (tree name, enum value_range_kind range_type,
 			       struct range_info_def *range_info)
 {
@@ -743,6 +743,14 @@ duplicate_ssa_name_range_info (tree name, enum value_range_kind range_type,
   SSA_NAME_RANGE_INFO (name) = new_range_info;
 }
 
+void
+duplicate_ssa_name_range_info (tree name, tree src)
+{
+  gcc_checking_assert (!POINTER_TYPE_P (TREE_TYPE (src)));
+  duplicate_ssa_name_range_info (name,
+				 SSA_NAME_RANGE_TYPE (src),
+				 SSA_NAME_RANGE_INFO (src));
+}
 
 
 /* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h
index 7538ba9b706..8c419b13e6a 100644
--- a/gcc/tree-ssanames.h
+++ b/gcc/tree-ssanames.h
@@ -67,8 +67,6 @@ struct GTY ((variable_size)) range_info_def {
     if (VAR)
 
 /* Sets the value range to SSA.  */
-extern void set_range_info (tree, enum value_range_kind, const wide_int_ref &,
-			    const wide_int_ref &);
 extern void set_range_info (tree, const value_range &);
 extern void set_nonzero_bits (tree, const wide_int_ref &);
 extern wide_int get_nonzero_bits (const_tree);
@@ -92,8 +90,7 @@ extern void set_ptr_nonnull (tree);
 extern tree copy_ssa_name_fn (struct function *, tree, gimple *);
 extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
 extern tree duplicate_ssa_name_fn (struct function *, tree, gimple *);
-extern void duplicate_ssa_name_range_info (tree, enum value_range_kind,
-					   struct range_info_def *);
+extern void duplicate_ssa_name_range_info (tree dest, tree src);
 extern void reset_flow_sensitive_info (tree);
 extern void reset_flow_sensitive_info_in_bb (basic_block);
 extern void release_defs (gimple *);
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index e4381eb7079..3eddda66a66 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -2056,22 +2056,28 @@ vect_gen_vector_loop_niters (loop_vec_info loop_vinfo, tree niters,
       if (stmts != NULL && log_vf)
 	{
 	  if (niters_no_overflow)
-	    set_range_info (niters_vector, VR_RANGE,
-			    wi::one (TYPE_PRECISION (type)),
-			    wi::rshift (wi::max_value (TYPE_PRECISION (type),
-						       TYPE_SIGN (type)),
-					exact_log2 (const_vf),
-					TYPE_SIGN (type)));
+	    {
+	      value_range vr (type,
+			      wi::one (TYPE_PRECISION (type)),
+			      wi::rshift (wi::max_value (TYPE_PRECISION (type),
+							 TYPE_SIGN (type)),
+					  exact_log2 (const_vf),
+					  TYPE_SIGN (type)));
+	      set_range_info (niters_vector, vr);
+	    }
 	  /* For VF == 1 the vector IV might also overflow so we cannot
 	     assert a minimum value of 1.  */
 	  else if (const_vf > 1)
-	    set_range_info (niters_vector, VR_RANGE,
-			    wi::one (TYPE_PRECISION (type)),
-			    wi::rshift (wi::max_value (TYPE_PRECISION (type),
-						       TYPE_SIGN (type))
-					- (const_vf - 1),
-					exact_log2 (const_vf), TYPE_SIGN (type))
-			    + 1);
+	    {
+	      value_range vr (type,
+			      wi::one (TYPE_PRECISION (type)),
+			      wi::rshift (wi::max_value (TYPE_PRECISION (type),
+							 TYPE_SIGN (type))
+					  - (const_vf - 1),
+					  exact_log2 (const_vf), TYPE_SIGN (type))
+			      + 1);
+	      set_range_info (niters_vector, vr);
+	    }
 	}
     }
   *niters_vector_ptr = niters_vector;
@@ -2888,9 +2894,12 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1,
       /* It's guaranteed that vector loop bound before vectorization is at
 	 least VF, so set range information for newly generated var.  */
       if (new_var_p)
-	set_range_info (niters, VR_RANGE,
-			wi::to_wide (build_int_cst (type, vf)),
-			wi::to_wide (TYPE_MAX_VALUE (type)));
+	{
+	  value_range vr (type,
+			  wi::to_wide (build_int_cst (type, vf)),
+			  wi::to_wide (TYPE_MAX_VALUE (type)));
+	  set_range_info (niters, vr);
+	}
 
       /* Prolog iterates at most bound_prolog times, latch iterates at
 	 most bound_prolog - 1 times.  */
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index e9f19d0c8b9..ab6aa11c044 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -3742,9 +3742,16 @@ vrp_asserts::remove_range_assertions ()
 		    && all_imm_uses_in_stmt_or_feed_cond (var, stmt,
 							  single_pred (bb)))
 		  {
-		    set_range_info (var, SSA_NAME_RANGE_TYPE (lhs),
-				    SSA_NAME_RANGE_INFO (lhs)->get_min (),
-				    SSA_NAME_RANGE_INFO (lhs)->get_max ());
+		    /* We could use duplicate_ssa_name_range_info here
+		       instead of peeking inside SSA_NAME_RANGE_INFO,
+		       but the aforementioned asserts that the
+		       destination has no global range.  This is
+		       slated for removal anyhow.  */
+		    value_range r (TREE_TYPE (lhs),
+				   SSA_NAME_RANGE_INFO (lhs)->get_min (),
+				   SSA_NAME_RANGE_INFO (lhs)->get_max (),
+				   SSA_NAME_RANGE_TYPE (lhs));
+		    set_range_info (var, r);
 		    maybe_set_nonzero_bits (single_pred_edge (bb), var);
 		  }
 	      }
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index f94da3130e3..122586fbcc8 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -2980,9 +2980,12 @@ simplify_using_ranges::simplify_truth_ops_using_ranges
       gsi_insert_before (gsi, newop, GSI_SAME_STMT);
       if (INTEGRAL_TYPE_P (TREE_TYPE (tem))
 	  && TYPE_PRECISION (TREE_TYPE (tem)) > 1)
-	set_range_info (tem, VR_RANGE,
-			wi::zero (TYPE_PRECISION (TREE_TYPE (tem))),
-			wi::one (TYPE_PRECISION (TREE_TYPE (tem))));
+	{
+	  value_range vr (TREE_TYPE (tem),
+			  wi::zero (TYPE_PRECISION (TREE_TYPE (tem))),
+			  wi::one (TYPE_PRECISION (TREE_TYPE (tem))));
+	  set_range_info (tem, vr);
+	}
       gimple_assign_set_rhs_with_ops (gsi, NOP_EXPR, tem);
     }
   /* Or without.  */
-- 
2.35.1


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

* [COMMITTED] Remove various deprecated methods in class irange.
  2022-04-29  9:02 [COMMITTED] Make irange::intersect(wide_int, wide_int) private Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Call set_undefined from irange constructor Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Prefer global range info setters that take a range Aldy Hernandez
@ 2022-04-29  9:02 ` Aldy Hernandez
  2022-04-29  9:02 ` [COMMITTED] Move common code from range-op.cc to header files Aldy Hernandez
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-04-29  9:02 UTC (permalink / raw)
  To: GCC patches

This patch cleans up some irange methods in preparation for other
cleanups later in the cycle.

First, we prefer the reference overloads for union and intersect as
the pointer versions have been deprecated for a couple releases.

Also, I've renamed the legacy union/intersect whose only function was
to provide additional verbosity for VRP into
legacy_verbose_{union,intersect}.  This is a temporary rename to serve
as a visual reminder of which of the methods are bound for the chopping
block when the legacy code gets removed later this cycle.

Tested on x86-64 Linux.

gcc/ChangeLog:

	* gimple-fold.cc (size_must_be_zero_p): Use reference
	instead of pointer
	* gimple-ssa-evrp-analyze.cc
	(evrp_range_analyzer::record_ranges_from_incoming_edge): Rename
	intersect to legacy_verbose_intersect.
	* ipa-cp.cc (ipcp_vr_lattice::meet_with_1): Use reference instead
	of pointer.
	* tree-ssa-dom.cc (dom_jt_simplifier::simplify): Use value_range
	instead of value_range_equiv.
	* tree-vrp.cc (extract_range_from_plus_minus_expr): Use reference
	instead of pointer.
	(find_case_label_range): Same.
	* value-range-equiv.cc (value_range_equiv::intersect): Rename to...
	(value_range_equiv::legacy_verbose_intersect): ...this.
	(value_range_equiv::union_): Rename to...
	(value_range_equiv::legacy_verbose_union_): ...this.
	* value-range-equiv.h (class value_range_equiv): Rename union and
	intersect to legacy_verbose_{intersect,union}.
	* value-range.cc (irange::union_): Rename to...
	(irange::legacy_verbose_union_): ...this.
	(irange::intersect): Rename to...
	(irange::legacy_verbose_intersect): ...this.
	* value-range.h (irange::union_): Rename union_ to
	legacy_verbose_union.
	(irange::intersect): Rename intersect to legacy_verbose_intersect.
	* vr-values.cc (vr_values::update_value_range): Same.
	(vr_values::extract_range_for_var_from_comparison_expr): Same.
	(vr_values::extract_range_from_cond_expr): Rename union_ to
	legacy_verbose_union.
	(vr_values::extract_range_from_phi_node): Same.
---
 gcc/gimple-fold.cc             |  2 +-
 gcc/gimple-ssa-evrp-analyze.cc |  2 +-
 gcc/ipa-cp.cc                  |  2 +-
 gcc/tree-ssa-dom.cc            |  2 +-
 gcc/tree-vrp.cc                |  8 ++++----
 gcc/value-range-equiv.cc       |  4 ++--
 gcc/value-range-equiv.h        |  4 ++--
 gcc/value-range.cc             |  4 ++--
 gcc/value-range.h              |  8 ++++----
 gcc/vr-values.cc               | 12 ++++++------
 10 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 863ee3d3912..7baec119ba3 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -883,7 +883,7 @@ size_must_be_zero_p (tree size)
     get_global_range_query ()->range_of_expr (vr, size);
   if (vr.undefined_p ())
     vr.set_varying (TREE_TYPE (size));
-  vr.intersect (&valid_range);
+  vr.intersect (valid_range);
   return vr.zero_p ();
 }
 
diff --git a/gcc/gimple-ssa-evrp-analyze.cc b/gcc/gimple-ssa-evrp-analyze.cc
index 5b6c9f8fe1b..fec6e87ba80 100644
--- a/gcc/gimple-ssa-evrp-analyze.cc
+++ b/gcc/gimple-ssa-evrp-analyze.cc
@@ -207,7 +207,7 @@ evrp_range_analyzer::record_ranges_from_incoming_edge (basic_block bb)
 	      const value_range_equiv *old_vr
 		= get_value_range (vrs[i].first);
 	      value_range tem (*old_vr);
-	      tem.intersect (vrs[i].second);
+	      tem.legacy_verbose_intersect (vrs[i].second);
 	      if (tem.equal_p (*old_vr))
 		{
 		  free_value_range (vrs[i].second);
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index dc3f0e94b17..11f4a327b99 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -1018,7 +1018,7 @@ ipcp_vr_lattice::meet_with_1 (const value_range *other_vr)
     return set_to_bottom ();
 
   value_range save (m_vr);
-  m_vr.union_ (other_vr);
+  m_vr.union_ (*other_vr);
   return !m_vr.equal_p (save);
 }
 
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 21745bf31d3..4a0cf2ef54c 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -694,7 +694,7 @@ dom_jt_simplifier::simplify (gimple *stmt, gimple *within_stmt,
       if (TREE_CODE (op) != SSA_NAME)
 	return NULL_TREE;
 
-      const value_range_equiv *vr = m_vr_values->get_value_range (op);
+      const value_range *vr = m_vr_values->get_value_range (op);
       return find_case_label_range (switch_stmt, vr);
     }
   if (gassign *assign_stmt = dyn_cast <gassign *> (stmt))
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index ab6aa11c044..0cbd9d369ca 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -768,7 +768,7 @@ extract_range_from_plus_minus_expr (value_range *vr,
 	  value_range vrres;
 	  extract_range_from_plus_minus_expr (&vrres, code, expr_type,
 					      &vrtem1, vr1_);
-	  vr->union_ (&vrres);
+	  vr->union_ (vrres);
 	}
       return;
     }
@@ -782,7 +782,7 @@ extract_range_from_plus_minus_expr (value_range *vr,
 	  value_range vrres;
 	  extract_range_from_plus_minus_expr (&vrres, code, expr_type,
 					      vr0_, &vrtem1);
-	  vr->union_ (&vrres);
+	  vr->union_ (vrres);
 	}
       return;
     }
@@ -2470,7 +2470,7 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
       int_range_max label_range (CASE_LOW (label), case_high);
       if (!types_compatible_p (label_range.type (), range_of_op->type ()))
 	range_cast (label_range, range_of_op->type ());
-      label_range.intersect (range_of_op);
+      label_range.intersect (*range_of_op);
       if (label_range == *range_of_op)
 	return label;
     }
@@ -2494,7 +2494,7 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
       int_range_max label_range (CASE_LOW (min_label), case_high);
       if (!types_compatible_p (label_range.type (), range_of_op->type ()))
 	range_cast (label_range, range_of_op->type ());
-      label_range.intersect (range_of_op);
+      label_range.intersect (*range_of_op);
       if (label_range.undefined_p ())
 	return gimple_switch_label (switch_stmt, 0);
     }
diff --git a/gcc/value-range-equiv.cc b/gcc/value-range-equiv.cc
index 731fa53941d..77c6f5ca99d 100644
--- a/gcc/value-range-equiv.cc
+++ b/gcc/value-range-equiv.cc
@@ -188,7 +188,7 @@ value_range_equiv::equiv_add (const_tree var,
 }
 
 void
-value_range_equiv::intersect (const value_range_equiv *other)
+value_range_equiv::legacy_verbose_intersect (const value_range_equiv *other)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
@@ -238,7 +238,7 @@ value_range_equiv::intersect (const value_range_equiv *other)
 }
 
 void
-value_range_equiv::union_ (const value_range_equiv *other)
+value_range_equiv::legacy_verbose_union_ (const value_range_equiv *other)
 {
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
diff --git a/gcc/value-range-equiv.h b/gcc/value-range-equiv.h
index 11b806c9141..0aa1069cb61 100644
--- a/gcc/value-range-equiv.h
+++ b/gcc/value-range-equiv.h
@@ -48,8 +48,8 @@ class GTY((user)) value_range_equiv : public value_range
 
   bool operator== (const value_range_equiv &) const /* = delete */;
   bool operator!= (const value_range_equiv &) const /* = delete */;
-  void intersect (const value_range_equiv *);
-  void union_ (const value_range_equiv *);
+  void legacy_verbose_intersect (const value_range_equiv *);
+  void legacy_verbose_union_ (const value_range_equiv *);
   bool equal_p (const value_range_equiv &, bool ignore_equivs) const;
 
   /* Types of value ranges.  */
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 000bbcf8917..94301b32c37 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -1442,7 +1442,7 @@ irange::legacy_union (irange *vr0, const irange *vr1)
    may not be the smallest possible such range.  */
 
 void
-irange::union_ (const irange *other)
+irange::legacy_verbose_union_ (const irange *other)
 {
   if (legacy_mode_p ())
     {
@@ -1482,7 +1482,7 @@ irange::union_ (const irange *other)
 }
 
 void
-irange::intersect (const irange *other)
+irange::legacy_verbose_intersect (const irange *other)
 {
   if (legacy_mode_p ())
     {
diff --git a/gcc/value-range.h b/gcc/value-range.h
index b64e02426ca..90a395f4d73 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -96,8 +96,8 @@ public:
   bool may_contain_p (tree) const;		// DEPRECATED
   void set (tree);				// DEPRECATED
   bool equal_p (const irange &) const;		// DEPRECATED
-  void union_ (const class irange *);		// DEPRECATED
-  void intersect (const irange *);		// DEPRECATED
+  void legacy_verbose_union_ (const class irange *);	// DEPRECATED
+  void legacy_verbose_intersect (const irange *);	// DEPRECATED
 
 protected:
   irange (tree *, unsigned);
@@ -549,7 +549,7 @@ irange::union_ (const irange &r)
 {
   dump_flags_t m_flags = dump_flags;
   dump_flags &= ~TDF_DETAILS;
-  irange::union_ (&r);
+  irange::legacy_verbose_union_ (&r);
   dump_flags = m_flags;
 }
 
@@ -558,7 +558,7 @@ irange::intersect (const irange &r)
 {
   dump_flags_t m_flags = dump_flags;
   dump_flags &= ~TDF_DETAILS;
-  irange::intersect (&r);
+  irange::legacy_verbose_intersect (&r);
   dump_flags = m_flags;
 }
 
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index 122586fbcc8..301996d2134 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -266,7 +266,7 @@ vr_values::update_value_range (const_tree var, value_range_equiv *new_vr)
       value_range_equiv nr;
       get_global_range_query ()->range_of_expr (nr, const_cast <tree> (var));
       if (!nr.undefined_p ())
-	new_vr->intersect (&nr);
+	new_vr->legacy_verbose_intersect (&nr);
     }
 
   /* Update the value range, if necessary.  If we cannot allocate a lattice
@@ -750,7 +750,7 @@ vr_values::extract_range_for_var_from_comparison_expr (tree var,
     gcc_unreachable ();
 
   /* Finally intersect the new range with what we already know about var.  */
-  vr_p->intersect (get_value_range (var));
+  vr_p->legacy_verbose_intersect (get_value_range (var));
 }
 
 /* Extract value range information from an ASSERT_EXPR EXPR and store
@@ -1014,7 +1014,7 @@ vr_values::extract_range_from_cond_expr (value_range_equiv *vr, gassign *stmt)
 
   /* The resulting value range is the union of the operand ranges */
   vr->deep_copy (vr0);
-  vr->union_ (vr1);
+  vr->legacy_verbose_union_ (vr1);
 }
 
 
@@ -2300,10 +2300,10 @@ simplify_using_ranges::vrp_evaluate_conditional_warnv_with_ops
 	     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.intersect (vr0);
+	  vro.legacy_verbose_intersect (vr0);
 	  if (vro.undefined_p ())
 	    return boolean_false_node;
-	  vri.intersect (vr0);
+	  vri.legacy_verbose_intersect (vr0);
 	  if (vri.undefined_p ())
 	    return boolean_true_node;
 	}
@@ -2803,7 +2803,7 @@ vr_values::extract_range_from_phi_node (gphi *phi,
 	  if (first)
 	    vr_result->deep_copy (vr_arg);
 	  else
-	    vr_result->union_ (vr_arg);
+	    vr_result->legacy_verbose_union_ (vr_arg);
 	  first = false;
 
 	  if (vr_result->varying_p ())
-- 
2.35.1


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

* [COMMITTED] Move common code from range-op.cc to header files.
  2022-04-29  9:02 [COMMITTED] Make irange::intersect(wide_int, wide_int) private Aldy Hernandez
                   ` (2 preceding siblings ...)
  2022-04-29  9:02 ` [COMMITTED] Remove various deprecated methods in class irange Aldy Hernandez
@ 2022-04-29  9:02 ` Aldy Hernandez
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-04-29  9:02 UTC (permalink / raw)
  To: GCC patches

In preparation for the agnostication of ranger, this patch moves
common code that can be shared with non-integer ranges (initially
pointers) into the relevant header files.

This is a relatively non-invasive change, as any changes that would
need to be ported to GCC 12, would occur in the range-op entries
themselves, not in the supporting glue which I'm moving.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

	* range-op.cc (empty_range_varying): Move to range-op.h.
	(range_true): Move to range.h.
	(range_false): Same.
	(range_true_and_false): Same.
	(enum bool_range_state): Move to range-op.h.
	(relop_early_resolve): Same.
	(operator_equal::op1_op2_relation): Abstract code to...
	(equal_op1_op2_relation): ...here.
	(operator_not_equal::op1_op2_relation): Abstract code to...
	(not_equal_op1_op2_relation): ...here.
	(operator_lt::op1_op2_relation): Abstract code to...
	(lt_op1_op2_relation): ...here.
	(operator_le::op1_op2_relation): Abstract code to...
	(le_op1_op2_relation): ...here.
	(operator_gt::op1_op2_relation): Abstract code to...
	(gt_op1_op2_relation): ...here.
	(operator_ge::op1_op2_relation): Abstract code to...
	(ge_op1_op2_relation): ...here.
	(class range_op_table): Move to range-op.h.
	* range-op.h (equal_op1_op2_relation): Moved from range-op.cc.
	(not_equal_op1_op2_relation): Same.
	(lt_op1_op2_relation): Same.
	(le_op1_op2_relation): Same.
	(gt_op1_op2_relation): Same.
	(ge_op1_op2_relation): Same.
	(enum bool_range_state): Same.
	(get_bool_state): Same.
	(empty_range_varying): Same.
	(relop_early_resolve): Same.
	(class range_op_table): Same.
	* range.h (range_true): Same.
	(range_false): Same.
	(range_true_and_false): Same.
---
 gcc/range-op.cc | 140 +++++++++++++++---------------------------------
 gcc/range-op.h  |  72 +++++++++++++++++++++++++
 gcc/range.h     |  28 ++++++++++
 3 files changed, 143 insertions(+), 97 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 464a1f839fd..fa962507b92 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -63,24 +63,6 @@ min_limit (const_tree type)
   return wi::min_value (TYPE_PRECISION (type) , TYPE_SIGN (type));
 }
 
-// If the range of either op1 or op2 is undefined, set the result to
-// varying and return TRUE.  If the caller truely cares about a result,
-// they should pass in a varying if it has an undefined that it wants
-// treated as a varying.
-
-inline bool
-empty_range_varying (irange &r, tree type,
-		     const irange &op1, const irange & op2)
-{
-  if (op1.undefined_p () || op2.undefined_p ())
-    {
-      r.set_varying (type);
-      return true;
-    }
-  else
-    return false;
-}
-
 // Return false if shifting by OP is undefined behavior.  Otherwise, return
 // true and the range it is to be shifted by.  This allows trimming out of
 // undefined ranges, leaving only valid ranges if there are any.
@@ -432,39 +414,10 @@ create_possibly_reversed_range (irange &r, tree type,
     r.set (wide_int_to_tree (type, new_lb), wide_int_to_tree (type, new_ub));
 }
 
-// Return an irange instance that is a boolean TRUE.
-
-static inline int_range<1>
-range_true (tree type)
-{
-  unsigned prec = TYPE_PRECISION (type);
-  return int_range<1> (type, wi::one (prec), wi::one (prec));
-}
-
-// Return an irange instance that is a boolean FALSE.
-
-static inline int_range<1>
-range_false (tree type)
-{
-  unsigned prec = TYPE_PRECISION (type);
-  return int_range<1> (type, wi::zero (prec), wi::zero (prec));
-}
-
-// Return an irange that covers both true and false.
-
-static inline int_range<1>
-range_true_and_false (tree type)
-{
-  unsigned prec = TYPE_PRECISION (type);
-  return int_range<1> (type, wi::zero (prec), wi::one (prec));
-}
-
-enum bool_range_state { BRS_FALSE, BRS_TRUE, BRS_EMPTY, BRS_FULL };
-
 // Return the summary information about boolean range LHS.  If EMPTY/FULL,
 // return the equivalent range for TYPE in R; if FALSE/TRUE, do nothing.
 
-static bool_range_state
+bool_range_state
 get_bool_state (irange &r, const irange &lhs, tree val_type)
 {
   // If there is no result, then this is unexecutable.
@@ -488,37 +441,6 @@ get_bool_state (irange &r, const irange &lhs, tree val_type)
   return BRS_TRUE;
 }
 
-// For relation opcodes, first try to see if the supplied relation
-// forces a true or false result, and return that.
-// Then check for undefined operands.  If none of this applies,
-// return false.
-
-static inline bool
-relop_early_resolve (irange &r, tree type, const irange &op1,
-		     const irange &op2, relation_kind rel,
-		     relation_kind my_rel)
-{
-  // If known relation is a complete subset of this relation, always true.
-  if (relation_union (rel, my_rel) == my_rel)
-    {
-      r = range_true (type);
-      return true;
-    }
-
-  // If known relation has no subset of this relation, always false.
-  if (relation_intersect (rel, my_rel) == VREL_EMPTY)
-    {
-      r = range_false (type);
-      return true;
-    }
-
-  // If either operand is undefined, return VARYING.
-  if (empty_range_varying (r, type, op1, op2))
-    return true;
-
-  return false;
-}
-
 
 class operator_equal : public range_operator
 {
@@ -541,7 +463,7 @@ public:
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 enum tree_code
-operator_equal::op1_op2_relation (const irange &lhs) const
+equal_op1_op2_relation (const irange &lhs)
 {
   if (lhs.undefined_p ())
     return VREL_EMPTY;
@@ -556,6 +478,12 @@ operator_equal::op1_op2_relation (const irange &lhs) const
   return VREL_NONE;
 }
 
+enum tree_code
+operator_equal::op1_op2_relation (const irange &lhs) const
+{
+  return equal_op1_op2_relation (lhs);
+}
+
 
 bool
 operator_equal::fold_range (irange &r, tree type,
@@ -651,7 +579,7 @@ public:
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 enum tree_code
-operator_not_equal::op1_op2_relation (const irange &lhs) const
+not_equal_op1_op2_relation (const irange &lhs)
 {
   if (lhs.undefined_p ())
     return VREL_EMPTY;
@@ -666,6 +594,12 @@ operator_not_equal::op1_op2_relation (const irange &lhs) const
   return VREL_NONE;
 }
 
+enum tree_code
+operator_not_equal::op1_op2_relation (const irange &lhs) const
+{
+  return not_equal_op1_op2_relation (lhs);
+}
+
 bool
 operator_not_equal::fold_range (irange &r, tree type,
 				const irange &op1,
@@ -821,7 +755,7 @@ public:
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 enum tree_code
-operator_lt::op1_op2_relation (const irange &lhs) const
+lt_op1_op2_relation (const irange &lhs)
 {
   if (lhs.undefined_p ())
     return VREL_EMPTY;
@@ -836,6 +770,12 @@ operator_lt::op1_op2_relation (const irange &lhs) const
   return VREL_NONE;
 }
 
+enum tree_code
+operator_lt::op1_op2_relation (const irange &lhs) const
+{
+  return lt_op1_op2_relation (lhs);
+}
+
 bool
 operator_lt::fold_range (irange &r, tree type,
 			 const irange &op1,
@@ -923,7 +863,7 @@ public:
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 enum tree_code
-operator_le::op1_op2_relation (const irange &lhs) const
+le_op1_op2_relation (const irange &lhs)
 {
   if (lhs.undefined_p ())
     return VREL_EMPTY;
@@ -938,6 +878,12 @@ operator_le::op1_op2_relation (const irange &lhs) const
   return VREL_NONE;
 }
 
+enum tree_code
+operator_le::op1_op2_relation (const irange &lhs) const
+{
+  return le_op1_op2_relation (lhs);
+}
+
 bool
 operator_le::fold_range (irange &r, tree type,
 			 const irange &op1,
@@ -1025,7 +971,7 @@ public:
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 enum tree_code
-operator_gt::op1_op2_relation (const irange &lhs) const
+gt_op1_op2_relation (const irange &lhs)
 {
   if (lhs.undefined_p ())
     return VREL_EMPTY;
@@ -1040,6 +986,12 @@ operator_gt::op1_op2_relation (const irange &lhs) const
   return VREL_NONE;
 }
 
+enum tree_code
+operator_gt::op1_op2_relation (const irange &lhs) const
+{
+  return gt_op1_op2_relation (lhs);
+}
+
 
 bool
 operator_gt::fold_range (irange &r, tree type,
@@ -1126,7 +1078,7 @@ public:
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
 enum tree_code
-operator_ge::op1_op2_relation (const irange &lhs) const
+ge_op1_op2_relation (const irange &lhs)
 {
   if (lhs.undefined_p ())
     return VREL_EMPTY;
@@ -1141,6 +1093,12 @@ operator_ge::op1_op2_relation (const irange &lhs) const
   return VREL_NONE;
 }
 
+enum tree_code
+operator_ge::op1_op2_relation (const irange &lhs) const
+{
+  return ge_op1_op2_relation (lhs);
+}
+
 bool
 operator_ge::fold_range (irange &r, tree type,
 			 const irange &op1,
@@ -3993,18 +3951,6 @@ pointer_or_operator::wi_fold (irange &r, tree type,
     r.set_varying (type);
 }
 \f
-// This implements the range operator tables as local objects in this file.
-
-class range_op_table
-{
-public:
-  inline range_operator *operator[] (enum tree_code code);
-protected:
-  void set (enum tree_code code, range_operator &op);
-private:
-  range_operator *m_range_tree[MAX_TREE_CODES];
-};
-
 // Return a pointer to the range_operator instance, if there is one
 // associated with tree_code CODE.
 
diff --git a/gcc/range-op.h b/gcc/range-op.h
index a51969c2211..c93eb844547 100644
--- a/gcc/range-op.h
+++ b/gcc/range-op.h
@@ -112,4 +112,76 @@ extern void wi_set_zero_nonzero_bits (tree type,
 				      wide_int &maybe_nonzero,
 				      wide_int &mustbe_nonzero);
 
+// op1_op2_relation methods that are the same across irange and frange.
+enum tree_code equal_op1_op2_relation (const irange &lhs);
+enum tree_code not_equal_op1_op2_relation (const irange &lhs);
+enum tree_code lt_op1_op2_relation (const irange &lhs);
+enum tree_code le_op1_op2_relation (const irange &lhs);
+enum tree_code gt_op1_op2_relation (const irange &lhs);
+enum tree_code ge_op1_op2_relation (const irange &lhs);
+
+enum bool_range_state { BRS_FALSE, BRS_TRUE, BRS_EMPTY, BRS_FULL };
+bool_range_state get_bool_state (irange &r, const irange &lhs, tree val_type);
+
+// If the range of either op1 or op2 is undefined, set the result to
+// varying and return TRUE.  If the caller truely cares about a result,
+// they should pass in a varying if it has an undefined that it wants
+// treated as a varying.
+
+inline bool
+empty_range_varying (irange &r, tree type,
+		     const irange &op1, const irange & op2)
+{
+  if (op1.undefined_p () || op2.undefined_p ())
+    {
+      r.set_varying (type);
+      return true;
+    }
+  else
+    return false;
+}
+
+// For relation opcodes, first try to see if the supplied relation
+// forces a true or false result, and return that.
+// Then check for undefined operands.  If none of this applies,
+// return false.
+
+inline bool
+relop_early_resolve (irange &r, tree type, const irange &op1,
+		     const irange &op2, relation_kind rel,
+		     relation_kind my_rel)
+{
+  // If known relation is a complete subset of this relation, always true.
+  if (relation_union (rel, my_rel) == my_rel)
+    {
+      r = range_true (type);
+      return true;
+    }
+
+  // If known relation has no subset of this relation, always false.
+  if (relation_intersect (rel, my_rel) == VREL_EMPTY)
+    {
+      r = range_false (type);
+      return true;
+    }
+
+  // If either operand is undefined, return VARYING.
+  if (empty_range_varying (r, type, op1, op2))
+    return true;
+
+  return false;
+}
+
+// This implements the range operator tables as local objects.
+
+class range_op_table
+{
+public:
+  range_operator *operator[] (enum tree_code code);
+protected:
+  void set (enum tree_code code, range_operator &op);
+private:
+  range_operator *m_range_tree[MAX_TREE_CODES];
+};
+
 #endif // GCC_RANGE_OP_H
diff --git a/gcc/range.h b/gcc/range.h
index 5eb784b2d54..5c70c66566c 100644
--- a/gcc/range.h
+++ b/gcc/range.h
@@ -25,4 +25,32 @@ value_range range_zero (tree type);
 value_range range_nonzero (tree type);
 value_range range_positives (tree type);
 value_range range_negatives (tree type);
+
+// Return an irange instance that is a boolean TRUE.
+
+static inline int_range<1>
+range_true (tree type)
+{
+  unsigned prec = TYPE_PRECISION (type);
+  return int_range<1> (type, wi::one (prec), wi::one (prec));
+}
+
+// Return an irange instance that is a boolean FALSE.
+
+static inline int_range<1>
+range_false (tree type)
+{
+  unsigned prec = TYPE_PRECISION (type);
+  return int_range<1> (type, wi::zero (prec), wi::zero (prec));
+}
+
+// Return an irange that covers both true and false.
+
+static inline int_range<1>
+range_true_and_false (tree type)
+{
+  unsigned prec = TYPE_PRECISION (type);
+  return int_range<1> (type, wi::zero (prec), wi::one (prec));
+}
+
 #endif // GCC_RANGE_H
-- 
2.35.1


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

end of thread, other threads:[~2022-04-29  9:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29  9:02 [COMMITTED] Make irange::intersect(wide_int, wide_int) private Aldy Hernandez
2022-04-29  9:02 ` [COMMITTED] Call set_undefined from irange constructor Aldy Hernandez
2022-04-29  9:02 ` [COMMITTED] Prefer global range info setters that take a range Aldy Hernandez
2022-04-29  9:02 ` [COMMITTED] Remove various deprecated methods in class irange Aldy Hernandez
2022-04-29  9:02 ` [COMMITTED] Move common code from range-op.cc to header files 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).