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/101462 - fix signedness of reused reduction vector
Date: Fri, 16 Jul 2021 09:41:15 +0200 (CEST)	[thread overview]
Message-ID: <np1s4qn-3629-ro8q-6noq-3rp43n2415r@fhfr.qr> (raw)

This fixes the partial reduction of the reused reduction vector to
carried out in the correct sign and the correctly signed vector
recorded for the skip edge use.

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

2021-07-16  Richard Biener  <rguenther@suse.de>

	* tree-vect-loop.c (vect_transform_cycle_phi): Correct sign
	conversion issues with the partial reduction of the reused
	vector accumulator.
---
 gcc/tree-vect-loop.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index fc3dab0d143..00a57b2ba62 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -7706,21 +7706,35 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo,
   if (auto *accumulator = reduc_info->reused_accumulator)
     {
       tree def = accumulator->reduc_input;
-      unsigned int nreduc;
-      bool res = constant_multiple_p (TYPE_VECTOR_SUBPARTS (TREE_TYPE (def)),
-				      TYPE_VECTOR_SUBPARTS (vectype_out),
-				      &nreduc);
-      gcc_assert (res);
-      if (nreduc != 1)
-	{
-	  /* Reduce the single vector to a smaller one.  */
+      if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def)))
+	{
+	  unsigned int nreduc;
+	  bool res = constant_multiple_p (TYPE_VECTOR_SUBPARTS
+					    (TREE_TYPE (def)),
+					  TYPE_VECTOR_SUBPARTS (vectype_out),
+					  &nreduc);
+	  gcc_assert (res);
 	  gimple_seq stmts = NULL;
-	  def = vect_create_partial_epilog (def, vectype_out,
-					    STMT_VINFO_REDUC_CODE (reduc_info),
-					    &stmts);
+	  /* Reduce the single vector to a smaller one.  */
+	  if (nreduc != 1)
+	    {
+	      /* Perform the reduction in the appropriate type.  */
+	      tree rvectype = vectype_out;
+	      if (!useless_type_conversion_p (TREE_TYPE (vectype_out),
+					      TREE_TYPE (TREE_TYPE (def))))
+		rvectype = build_vector_type (TREE_TYPE (TREE_TYPE (def)),
+					      TYPE_VECTOR_SUBPARTS
+						(vectype_out));
+	      def = vect_create_partial_epilog (def, rvectype,
+						STMT_VINFO_REDUC_CODE
+						  (reduc_info),
+						&stmts);
+	    }
 	  /* Adjust the input so we pick up the partially reduced value
 	     for the skip edge in vect_create_epilog_for_reduction.  */
 	  accumulator->reduc_input = def;
+	  if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def)))
+	    def = gimple_convert (&stmts, vectype_out, def);
 	  if (loop_vinfo->main_loop_edge)
 	    {
 	      /* While we'd like to insert on the edge this will split
-- 
2.26.2

                 reply	other threads:[~2021-07-16  7:41 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=np1s4qn-3629-ro8q-6noq-3rp43n2415r@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).