public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Convert some uses in ranger_cache and DOM to vrange.
@ 2022-07-24 15:04 Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Allow registering same SSA name relations in oracle Aldy Hernandez
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aldy Hernandez @ 2022-07-24 15:04 UTC (permalink / raw)
  To: GCC patches

Here are a few conversions to type agnostic vrange I found while
working on frange.

Tested on x86-64 Linux.

gcc/ChangeLog:

	* gimple-range-cache.cc (ranger_cache::edge_range): Convert to vrange.
	(ranger_cache::range_from_dom): Same.
	* tree-ssa-dom.cc
	(dom_opt_dom_walker::set_global_ranges_from_unreachable_edges): Same.
---
 gcc/gimple-range-cache.cc |  7 ++++---
 gcc/tree-ssa-dom.cc       | 18 ++++++++++--------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index f3292fccaee..d9e160c9a2a 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -960,7 +960,7 @@ ranger_cache::edge_range (vrange &r, edge e, tree name, enum rfd_mode mode)
   // If this is not an abnormal edge, check for inferred ranges on exit.
   if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0)
     m_exit.maybe_adjust_range (r, name, e->src);
-  int_range_max er;
+  Value_Range er (TREE_TYPE (name));
   if (m_gori.outgoing_edge_range_p (er, e, name, *this))
     r.intersect (er);
   return true;
@@ -1364,7 +1364,8 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb,
   basic_block prev_bb = start_bb;
 
   // Track any inferred ranges seen.
-  int_range_max infer (TREE_TYPE (name));
+  Value_Range infer (TREE_TYPE (name));
+  infer.set_varying (TREE_TYPE (name));
 
   // Range on entry to the DEF block should not be queried.
   gcc_checking_assert (start_bb != def_bb);
@@ -1431,7 +1432,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb,
   // Now process any blocks wit incoming edges that nay have adjustemnts.
   while (m_workback.length () > start_limit)
     {
-      int_range_max er;
+      Value_Range er (TREE_TYPE (name));
       prev_bb = m_workback.pop ();
       if (!single_pred_p (prev_bb))
 	{
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index f5e8f574997..44dc27b464c 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1233,20 +1233,22 @@ dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb)
 
   gimple *stmt = last_stmt (pred_e->src);
   tree name;
-  int_range_max r;
   if (stmt
       && gimple_code (stmt) == GIMPLE_COND
       && (name = gimple_cond_lhs (stmt))
       && TREE_CODE (name) == SSA_NAME
-      && r.supports_type_p (TREE_TYPE (name))
       && assert_unreachable_fallthru_edge_p (pred_e)
-      && all_uses_feed_or_dominated_by_stmt (name, stmt)
-      && m_ranger->range_on_edge (r, pred_e, name)
-      && !r.varying_p ()
-      && !r.undefined_p ())
+      && all_uses_feed_or_dominated_by_stmt (name, stmt))
     {
-      set_range_info (name, r);
-      maybe_set_nonzero_bits (pred_e, name);
+      Value_Range r (TREE_TYPE (name));
+
+      if (m_ranger->range_on_edge (r, pred_e, name)
+	  && !r.varying_p ()
+	  && !r.undefined_p ())
+	{
+	  set_range_info (name, r);
+	  maybe_set_nonzero_bits (pred_e, name);
+	}
     }
 }
 
-- 
2.36.1


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

* [COMMITTED] Allow registering same SSA name relations in oracle.
  2022-07-24 15:04 [COMMITTED] Convert some uses in ranger_cache and DOM to vrange Aldy Hernandez
@ 2022-07-24 15:04 ` Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Tweaks to global ranges Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Minor fixes to vr_values to not die on non integral types Aldy Hernandez
  2 siblings, 0 replies; 4+ messages in thread
From: Aldy Hernandez @ 2022-07-24 15:04 UTC (permalink / raw)
  To: GCC patches

Similarly to what we did for the relation oracle, but for the path
oracle.  This was found while working on frange, where we can test for
x == x while checking for NANness.

Tested on x86-64 Linux.

gcc/ChangeLog:

	* value-relation.cc (value_relation::set_relation): Remove assert.
	(path_oracle::register_relation): Exit when trying to register
	same SSA name relations.
---
 gcc/value-relation.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index bd344253af3..a447021214f 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -667,8 +667,6 @@ private:
 inline void
 value_relation::set_relation (relation_kind r, tree n1, tree n2)
 {
-  gcc_checking_assert (SSA_NAME_VERSION (n1) != SSA_NAME_VERSION (n2)
-		       || r == VREL_EQ);
   related = r;
   name1 = n1;
   name2 = n2;
@@ -1449,6 +1447,11 @@ void
 path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1,
 				tree ssa2)
 {
+  // If the 2 ssa_names are the same, do nothing.  An equivalence is implied,
+  // and no other relation makes sense.
+  if (ssa1 == ssa2)
+    return;
+
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
       value_relation vr (k, ssa1, ssa2);
-- 
2.36.1


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

* [COMMITTED] Tweaks to global ranges.
  2022-07-24 15:04 [COMMITTED] Convert some uses in ranger_cache and DOM to vrange Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Allow registering same SSA name relations in oracle Aldy Hernandez
@ 2022-07-24 15:04 ` Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Minor fixes to vr_values to not die on non integral types Aldy Hernandez
  2 siblings, 0 replies; 4+ messages in thread
From: Aldy Hernandez @ 2022-07-24 15:04 UTC (permalink / raw)
  To: GCC patches

The global get_nonzero_bits was previously returning -1 for
unsupported types.  I dropped this in the conversion to global ranges
and it's causing a problem in the frange work, where CCP is asking for
the nonzero bits of non-integral types.  CCP may require further
tweaks, but for now, restore the original behavior.

Also, I'm removing old checks for precision that no longer hold, now
that we handle various types for global ranges.

Tested on x86-64 Linux.

gcc/ChangeLog:

	* tree-ssanames.cc (get_nonzero_bits): Return -1 for unsupported
	types.
	* value-query.cc (get_ssa_name_range_info): Remove precision check.
---
 gcc/tree-ssanames.cc | 3 +--
 gcc/value-query.cc   | 9 +++------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc
index 9389454a5a7..5c5d0e346c4 100644
--- a/gcc/tree-ssanames.cc
+++ b/gcc/tree-ssanames.cc
@@ -489,13 +489,12 @@ get_nonzero_bits (const_tree name)
       return wi::shwi (-1, precision);
     }
 
-  if (!range_info_p (name))
+  if (!range_info_p (name) || !irange::supports_p (TREE_TYPE (name)))
     return wi::shwi (-1, precision);
 
   /* Optimization to get at the nonzero bits because we know the
      storage type.  This saves us measurable time compared to going
      through vrange_storage.  */
-  gcc_checking_assert (irange::supports_p (TREE_TYPE (name)));
   irange_storage_slot *ri
     = static_cast <irange_storage_slot *> (SSA_NAME_RANGE_INFO (name));
   return ri->get_nonzero_bits ();
diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index 51911bdd1d0..3560d19f1ae 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -280,16 +280,13 @@ get_ssa_name_range_info (vrange &r, const_tree name)
 
   void *ri = SSA_NAME_RANGE_INFO (name);
 
-  // Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
-  // with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision.
-  if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (name)))
-	      > 2 * HOST_BITS_PER_WIDE_INT))
-    r.set_varying (type);
-  else
+  if (ri)
     {
       vrange_storage vstore (NULL);
       vstore.get_vrange (ri, r, TREE_TYPE (name));
     }
+  else
+    r.set_varying (type);
 }
 
 // Return nonnull attribute of pointer NAME from SSA_NAME_PTR_INFO.
-- 
2.36.1


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

* [COMMITTED] Minor fixes to vr_values to not die on non integral types.
  2022-07-24 15:04 [COMMITTED] Convert some uses in ranger_cache and DOM to vrange Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Allow registering same SSA name relations in oracle Aldy Hernandez
  2022-07-24 15:04 ` [COMMITTED] Tweaks to global ranges Aldy Hernandez
@ 2022-07-24 15:04 ` Aldy Hernandez
  2 siblings, 0 replies; 4+ messages in thread
From: Aldy Hernandez @ 2022-07-24 15:04 UTC (permalink / raw)
  To: GCC patches

The legacy code in vr_values mostly works on integral types (with few
exceptions such as some conversions from float).  This patch makes
vr_values::range_of_expr not die when asked for a range of an
unsupported type.  It also keeps the min/max simplification code from
being called on non integrals, similarly to what many of the other
assignment code is doing.

This is all a nop on the current code, but will keep us from
misbehaving when VRP starts working on non-integrals.

Tested on x86-64 Linux.

gcc/ChangeLog:

	* value-query.cc (range_query::get_value_range): Add assert.
	* vr-values.cc (vr_values::range_of_expr): Make sure we don't ICE
	on unsupported types in vr_values.
	(simplify_using_ranges::simplify): Same.
---
 gcc/value-query.cc |  1 +
 gcc/vr-values.cc   | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index 3560d19f1ae..decf5aae1fe 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -167,6 +167,7 @@ range_query::free_value_range_equiv (value_range_equiv *v)
 const class value_range_equiv *
 range_query::get_value_range (const_tree expr, gimple *stmt)
 {
+  gcc_checking_assert (value_range_equiv::supports_p (TREE_TYPE (expr)));
   int_range_max r;
   if (range_of_expr (r, const_cast<tree> (expr), stmt))
     return new (equiv_alloc->allocate ()) value_range_equiv (r);
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index 6b9c630fed3..626a9189472 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -188,6 +188,17 @@ vr_values::range_of_expr (vrange &r, tree expr, gimple *stmt)
 	r = *vr;
       else
 	{
+	  if (!vr->supports_type_p (TREE_TYPE (expr)))
+	    {
+	      // vr_values::extract_range_basic() use of ranger's
+	      // fold_range() can create a situation where we are
+	      // asked for the range of an unsupported legacy type.
+	      // Since get_value_range() above will return varying for
+	      // such types, avoid copying incompatible range types.
+	      gcc_checking_assert (vr->varying_p ());
+	      r.set_varying (TREE_TYPE (expr));
+	      return true;
+	    }
 	  value_range tmp = *vr;
 	  tmp.normalize_symbolics ();
 	  r = tmp;
@@ -4375,7 +4386,9 @@ simplify_using_ranges::simplify (gimple_stmt_iterator *gsi)
 
 	case MIN_EXPR:
 	case MAX_EXPR:
-	  return simplify_min_or_max_using_ranges (gsi, stmt);
+	  if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
+	    return simplify_min_or_max_using_ranges (gsi, stmt);
+	  break;
 
 	case RSHIFT_EXPR:
 	  {
-- 
2.36.1


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

end of thread, other threads:[~2022-07-24 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-24 15:04 [COMMITTED] Convert some uses in ranger_cache and DOM to vrange Aldy Hernandez
2022-07-24 15:04 ` [COMMITTED] Allow registering same SSA name relations in oracle Aldy Hernandez
2022-07-24 15:04 ` [COMMITTED] Tweaks to global ranges Aldy Hernandez
2022-07-24 15:04 ` [COMMITTED] Minor fixes to vr_values to not die on non integral types 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).