]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/113863 - elide degenerate virtual PHIs when moving ee stores
authorRichard Biener <rguenther@suse.de>
Mon, 12 Feb 2024 09:40:42 +0000 (10:40 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 12 Feb 2024 10:52:29 +0000 (11:52 +0100)
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.

gcc/testsuite/gcc.dg/vect/pr113863.c [new file with mode: 0644]
gcc/tree-vect-data-refs.cc
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr113863.c b/gcc/testsuite/gcc.dg/vect/pr113863.c
new file mode 100644 (file)
index 0000000..ffe7602
--- /dev/null
@@ -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);
+    }
+}
index 2170d17e839564be18ad65ac3b0add9bb650b7de..c531079d3bbf972c05ee97246db5927b8ca53c98 100644 (file)
@@ -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);
index eed2268e9bae7e7ad36d13da03e0b54eab26ef6f..04f4b5b6b2fa76824c75b4d41df48ef995ad17a2 100644 (file)
@@ -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);