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-9292] tree-optimization/114192 - scalar reduction kept live with early break vect
Date: Mon,  4 Mar 2024 10:45:23 +0000 (GMT)	[thread overview]
Message-ID: <20240304104523.37585385842C@sourceware.org> (raw)

https://gcc.gnu.org/g:324d2907c86f05e40dc52d226940308f53a956c2

commit r14-9292-g324d2907c86f05e40dc52d226940308f53a956c2
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Mar 4 09:46:13 2024 +0100

    tree-optimization/114192 - scalar reduction kept live with early break vect
    
    The following fixes a missing replacement of the reduction value
    used in the epilog, causing the scalar reduction to be kept live
    across the early break exit path.
    
            PR tree-optimization/114192
            * tree-vect-loop.cc (vect_create_epilog_for_reduction): Use the
            appropriate def for the live out stmt in case of an alternate
            exit.

Diff:
---
 gcc/tree-vect-loop.cc | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 35f1f8c7d42..761cdc67570 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6066,20 +6066,32 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
 
   stmt_vec_info single_live_out_stmt[] = { stmt_info };
   array_slice<const stmt_vec_info> live_out_stmts = single_live_out_stmt;
-  if (slp_reduc)
-    /* All statements produce live-out values.  */
-    live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node);
-  else if (slp_node)
-    {
-      /* The last statement in the reduction chain produces the live-out
-	 value.  Note SLP optimization can shuffle scalar stmts to
-	 optimize permutations so we have to search for the last stmt.  */
-      for (k = 0; k < group_size; ++k)
-	if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k]))
-	  {
-	    single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k];
-	    break;
-	  }
+  if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
+      && loop_exit != LOOP_VINFO_IV_EXIT (loop_vinfo)
+      /* ???  We should fend this off earlier.  For conversions we create
+	 multiple epilogues, one dead.  */
+      && stmt_info == reduc_info->reduc_def)
+    {
+      gcc_assert (!slp_node);
+      single_live_out_stmt[0] = reduc_info;
+    }
+  else
+    {
+      if (slp_reduc)
+	/* All statements produce live-out values.  */
+	live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node);
+      else if (slp_node)
+	{
+	  /* The last statement in the reduction chain produces the live-out
+	     value.  Note SLP optimization can shuffle scalar stmts to
+	     optimize permutations so we have to search for the last stmt.  */
+	  for (k = 0; k < group_size; ++k)
+	    if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k]))
+	      {
+		single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k];
+		break;
+	      }
+	}
     }
 
   unsigned vec_num;

                 reply	other threads:[~2024-03-04 10:45 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=20240304104523.37585385842C@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).