public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [PR107009] Set ranges from unreachable edges for all known ranges.
@ 2022-09-26 12:18 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-09-26 12:18 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

In the conversion of DOM+evrp to DOM+ranger, we missed that evrp was
exporting ranges for unreachable edges for all SSA names for which we
have ranges for.  Instead we have only been exporting ranges for the
SSA name in the final conditional to the BB involving the unreachable
edge.

This patch adjusts adjusts DOM to iterate over the exports, similarly
to what evrp was doing.

Note that I also noticed that we don't calculate the nonzero bit mask
for op1, when 0 = op1 & MASK.  This isn't needed for this PR,
since maybe_set_nonzero_bits() is chasing the definition and
parsing the bitwise and on its own.  However, I'll be adding the
functionality for completeness sake, plus we could probably drop the
maybe_set_nonzero_bits legacy call entirely.

Tested and benchmarked on x86-64 Linux.

I'm going to push this as soon as a final round of testing is done, as I
shuffled a few things (cleanups) at the last minute.

	PR tree-optimization/107009

gcc/ChangeLog:

	* tree-ssa-dom.cc
	(dom_opt_dom_walker::set_global_ranges_from_unreachable_edges):
	Iterate over exports.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr107009.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr107009.c | 15 ++++++++++
 gcc/tree-ssa-dom.cc                      | 35 ++++++++++++------------
 2 files changed, 33 insertions(+), 17 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107009.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107009.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107009.c
new file mode 100644
index 00000000000..5010aed1723
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107009.c
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-dom2-alias" }
+
+typedef __SIZE_TYPE__ size_t;
+
+void saxpy(size_t n)
+{
+  if (n == 0 || n % 8 != 0)
+    __builtin_unreachable();
+
+  extern void foobar (size_t n);
+  foobar (n);
+}
+
+// { dg-final { scan-tree-dump "NONZERO.*fff8" "dom2" } }
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 513e0c88254..84bef798f52 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -1227,29 +1227,30 @@ void
 dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb)
 {
   edge pred_e = single_pred_edge_ignoring_loop_edges (bb, false);
-
   if (!pred_e)
     return;
 
   gimple *stmt = last_stmt (pred_e->src);
+  if (!stmt
+      || gimple_code (stmt) != GIMPLE_COND
+      || !assert_unreachable_fallthru_edge_p (pred_e))
+    return;
+
   tree name;
-  if (stmt
-      && gimple_code (stmt) == GIMPLE_COND
-      && (name = gimple_cond_lhs (stmt))
-      && TREE_CODE (name) == SSA_NAME
-      && assert_unreachable_fallthru_edge_p (pred_e)
-      && all_uses_feed_or_dominated_by_stmt (name, stmt))
-    {
-      Value_Range r (TREE_TYPE (name));
+  gori_compute &gori = m_ranger->gori ();
+  FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name)
+    if (all_uses_feed_or_dominated_by_stmt (name, stmt))
+      {
+	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);
-	}
-    }
+	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);
+	  }
+      }
 }
 
 /* Record any equivalences created by the incoming edge to BB into
-- 
2.37.1


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

only message in thread, other threads:[~2022-09-26 12:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 12:18 [PATCH] [PR107009] Set ranges from unreachable edges for all known ranges 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).