public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/103864 - SLP reduction of reductions with conversions
Date: Tue, 4 Jan 2022 10:16:21 +0100 (CET)	[thread overview]
Message-ID: <94o8qr6p-7o24-o6qn-1489-r89sor621rpo@fhfr.qr> (raw)

This generalizes the fix for PR103544 to also cover reductions that
are not reduction chains and does not consider reductions wrapped in
sign conversions for SLP reduction handling.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-01-04  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/103864
	PR tree-optimization/103544
	* tree-vect-slp.c (vect_analyze_slp_instance): Exclude
	reductions wrapped in conversions from SLP handling.
	(vect_analyze_slp): Revert PR103544 change.

	* gcc.dg/vect/pr103864.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr103864.c | 16 ++++++++++++++++
 gcc/tree-vect-slp.c                  | 18 +++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr103864.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr103864.c b/gcc/testsuite/gcc.dg/vect/pr103864.c
new file mode 100644
index 00000000000..464d5731a42
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr103864.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3 -fno-tree-reassoc" } */
+
+void
+crash_me (short int *crash_me_result, int i, char crash_me_ptr_0)
+{
+  while (i < 1)
+    {
+      int j;
+
+      for (j = 0; j < 2; ++j)
+        crash_me_result[j] += crash_me_ptr_0 + 1;
+
+      i += 3;
+    }
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 3566752c657..c3a1681d7c6 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -3325,8 +3325,13 @@ vect_analyze_slp_instance (vec_info *vinfo,
 	= as_a <loop_vec_info> (vinfo)->reductions;
       scalar_stmts.create (reductions.length ());
       for (i = 0; reductions.iterate (i, &next_info); i++)
-	if (STMT_VINFO_RELEVANT_P (next_info)
-	    || STMT_VINFO_LIVE_P (next_info))
+	if ((STMT_VINFO_RELEVANT_P (next_info)
+	     || STMT_VINFO_LIVE_P (next_info))
+	    /* ???  Make sure we didn't skip a conversion around a reduction
+	       path.  In that case we'd have to reverse engineer that conversion
+	       stmt following the chain using reduc_idx and from the PHI
+	       using reduc_def.  */
+	    && STMT_VINFO_DEF_TYPE (next_info) == vect_reduction_def)
 	  scalar_stmts.quick_push (next_info);
       /* If less than two were relevant/live there's nothing to SLP.  */
       if (scalar_stmts.length () < 2)
@@ -3419,13 +3424,8 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size)
 		vinfo = next;
 	      }
 	    STMT_VINFO_DEF_TYPE (first_element) = vect_internal_def;
-	    /* It can be still vectorized as part of an SLP reduction.
-	       ???  But only if we didn't skip a conversion around the group.
-	       In that case we'd have to reverse engineer that conversion
-	       stmt following the chain using reduc_idx and from the PHI
-	       using reduc_def.  */
-	    if (STMT_VINFO_DEF_TYPE (last) == vect_reduction_def)
-	      loop_vinfo->reductions.safe_push (last);
+	    /* It can be still vectorized as part of an SLP reduction.  */
+	    loop_vinfo->reductions.safe_push (last);
 	  }
 
       /* Find SLP sequences starting from groups of reductions.  */
-- 
2.31.1

                 reply	other threads:[~2022-01-04  9:16 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=94o8qr6p-7o24-o6qn-1489-r89sor621rpo@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@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).