public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8925] tree-optimization/113863 - elide degenerate virtual PHIs when moving ee stores
Date: Mon, 12 Feb 2024 10:52:59 +0000 (GMT)	[thread overview]
Message-ID: <20240212105259.204F33858D37@sourceware.org> (raw)

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

                 reply	other threads:[~2024-02-12 10:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240212105259.204F33858D37@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).