* [PATCH] tree-optimization/113863 - elide degenerate virtual PHIs when moving ee stores
@ 2024-02-12 10:25 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2024-02-12 10:25 UTC (permalink / raw)
To: gcc-patches
This makes sure to elide degenerate virtual PHIs when moving stores
across early exits.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
Richard.
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 | 17 +++++++++++++++++
gcc/tree-vect-data-refs.cc | 4 ++++
gcc/tree-vect-loop.cc | 19 +++++++++++++++++++
3 files changed, 40 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/vect/pr113863.c
diff --git a/gcc/testsuite/gcc.dg/vect/pr113863.c b/gcc/testsuite/gcc.dg/vect/pr113863.c
new file mode 100644
index 00000000000..ffe7602a846
--- /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 2170d17e839..c531079d3bb 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 eed2268e9ba..04f4b5b6b2f 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);
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-12 10:25 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:25 [PATCH] 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).