public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8925] tree-optimization/113863 - elide degenerate virtual PHIs when moving ee stores
@ 2024-02-12 10:52 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2024-02-12 10:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1e3f78dbb328a2f2db8def241372cb947d9cb7eb

commit r14-8925-g1e3f78dbb328a2f2db8def241372cb947d9cb7eb
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 12 10:40:42 2024 +0100

    tree-optimization/113863 - elide degenerate virtual PHIs when moving ee stores
    
    This makes sure to elide degenerate virtual PHIs when moving stores
    across early exits.
    
            PR tree-optimization/113863
            * tree-vect-data-refs.cc (vect_analyze_early_break_dependences):
            Record crossed virtual PHIs.
            * tree-vect-loop.cc (move_early_exit_stmts): Elide crossed
            virtual PHIs.
    
            * gcc.dg/vect/pr113863.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr113863.c | 17 +++++++++++++++++
 gcc/tree-vect-data-refs.cc           |  4 ++++
 gcc/tree-vect-loop.cc                | 19 +++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/pr113863.c b/gcc/testsuite/gcc.dg/vect/pr113863.c
new file mode 100644
index 000000000000..ffe7602a8463
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr113863.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-additional-options "-O3" } */
+
+void test_sort_helper(int *);
+int test_sort_driver_driver_real_last;
+void test_sort_driver_driver(int start, int *e, int *f)
+{
+  for (int *l = e; l > f;)
+    {
+      *--l = start;
+      if (f == l)
+	test_sort_helper(&test_sort_driver_driver_real_last);
+      if (start)
+	test_sort_driver_driver(start - 1, e, f);
+    }
+}
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 2170d17e8395..c531079d3bbf 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -812,6 +812,10 @@ vect_analyze_early_break_dependences (loop_vec_info loop_vinfo)
 	  break;
 	}
 
+      /* If we possibly sink through a virtual PHI make sure to elide that.  */
+      if (gphi *vphi = get_virtual_phi (bb))
+	LOOP_VINFO_EARLY_BRK_STORES (loop_vinfo).safe_push (vphi);
+
       /* All earlier blocks need dependence checking.  */
       check_deps = true;
       bb = single_pred (bb);
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index eed2268e9bae..04f4b5b6b2fa 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11789,6 +11789,25 @@ move_early_exit_stmts (loop_vec_info loop_vinfo)
 
   for (gimple *stmt : LOOP_VINFO_EARLY_BRK_STORES (loop_vinfo))
     {
+      /* We have to update crossed degenerate virtual PHIs.  Simply
+	 elide them.  */
+      if (gphi *vphi = dyn_cast <gphi *> (stmt))
+	{
+	  tree vdef = gimple_phi_result (vphi);
+	  tree vuse = gimple_phi_arg_def (vphi, 0);
+	  imm_use_iterator iter;
+	  use_operand_p use_p;
+	  gimple *use_stmt;
+	  FOR_EACH_IMM_USE_STMT (use_stmt, iter, vdef)
+	    {
+	      FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+		SET_USE (use_p, vuse);
+	    }
+	  auto gsi = gsi_for_stmt (stmt);
+	  remove_phi_node (&gsi, true);
+	  continue;
+	}
+
       /* Check to see if statement is still required for vect or has been
 	 elided.  */
       auto stmt_info = loop_vinfo->lookup_stmt (stmt);

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

only message in thread, other threads:[~2024-02-12 10:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 10:52 [gcc r14-8925] tree-optimization/113863 - elide degenerate virtual PHIs when moving ee stores Richard Biener

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).