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-9182] tree-optimization/114099 - virtual LC PHIs and early exit vect
Date: Mon, 26 Feb 2024 14:21:48 +0000 (GMT)	[thread overview]
Message-ID: <20240226142148.606133858C33@sourceware.org> (raw)

https://gcc.gnu.org/g:fb68e2cac1283f731a3a979cb714621afb1ddfcc

commit r14-9182-gfb68e2cac1283f731a3a979cb714621afb1ddfcc
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 26 12:27:42 2024 +0100

    tree-optimization/114099 - virtual LC PHIs and early exit vect
    
    In some cases exits can lack LC PHI nodes for the virtual operand.
    We have to create them when the epilog loop requires them which also
    allows us to remove some only halfway correct fixups.  This is the
    variant triggering for alternate exits.
    
            PR tree-optimization/114099
            * tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg):
            Create and fill in a needed virtual LC PHI for the alternate
            exits.  Remove code dealing with that missing.
    
            * gcc.dg/vect/vect-early-break_120-pr114099.c: New testcase.

Diff:
---
 .../gcc.dg/vect/vect-early-break_120-pr114099.c    | 20 +++++++++++++
 gcc/tree-vect-loop-manip.cc                        | 35 ++++++++--------------
 2 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c
new file mode 100644
index 000000000000..77e47e30417d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_120-pr114099.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "-O3" } */
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */
+
+int m;
+void __attribute__((noreturn)) n();
+void t1(int jj, int l) {
+  for (int i = 1; i < l; i++)
+  {
+    int p = m++;
+    if (p)
+      n();
+    if(jj <= i)
+      __builtin_unreachable();
+  }
+}
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 39bac1e99ef3..137b053ac359 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1667,17 +1667,18 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit,
 		  alt_loop_exit_block = split_edge (exit);
 		if (!need_virtual_phi)
 		  continue;
-		if (vphi_def)
-		  {
-		    if (!vphi)
-		      vphi = create_phi_node (copy_ssa_name (vphi_def),
-					      alt_loop_exit_block);
-		    else
-		      /* Edge redirection might re-allocate the PHI node
-			 so we have to rediscover it.  */
-		      vphi = get_virtual_phi (alt_loop_exit_block);
-		    add_phi_arg (vphi, vphi_def, exit, UNKNOWN_LOCATION);
-		  }
+		/* When the edge has no virtual LC PHI get at the live
+		   virtual operand by other means.  */
+		if (!vphi_def)
+		  vphi_def = get_live_virtual_operand_on_edge (exit);
+		if (!vphi)
+		  vphi = create_phi_node (copy_ssa_name (vphi_def),
+					  alt_loop_exit_block);
+		else
+		  /* Edge redirection might re-allocate the PHI node
+		     so we have to rediscover it.  */
+		  vphi = get_virtual_phi (alt_loop_exit_block);
+		add_phi_arg (vphi, vphi_def, exit, UNKNOWN_LOCATION);
 	      }
 
 	  set_immediate_dominator (CDI_DOMINATORS, new_preheader,
@@ -1789,17 +1790,7 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit,
 		  if (virtual_operand_p (alt_arg))
 		    {
 		      gphi *vphi = get_virtual_phi (alt_loop_exit_block);
-		      /* ???  When the exit yields to a path without
-			 any virtual use we can miss a LC PHI for the
-			 live virtual operand.  Simply choosing the
-			 one live at the start of the loop header isn't
-			 correct, but we should get here only with
-			 early-exit vectorization which will move all
-			 defs after the main exit, so leave a temporarily
-			 wrong virtual operand in place.  This happens
-			 for gcc.c-torture/execute/20150611-1.c  */
-		      if (vphi)
-			alt_arg = gimple_phi_result (vphi);
+		      alt_arg = gimple_phi_result (vphi);
 		    }
 		  /* For other live args we didn't create LC PHI nodes.
 		     Do so here.  */

                 reply	other threads:[~2024-02-26 14:21 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=20240226142148.606133858C33@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).