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][GCC 11] tree-optimization/109473 - fix type mismatch in reduction vectorization
Date: Wed, 3 May 2023 12:13:09 +0200 (CEST)	[thread overview]
Message-ID: <20230503101310.143791331F@imap2.suse-dmz.suse.de> (raw)

When backporting the PR109473 fix I failed to realize its testcase
will run into an unrelated similar bug.  With GCC 12 the code has
seen substantial refactoring so the following applies a local fix
to make sure we are using the correct types when building initial
values for reductions.

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

	PR tree-optimization/109473
	* tree-vect-loop.cc (get_initial_def_for_reduction):
	Convert the scalar values to the vector component type
	before using it to build the vector for the initial value.
---
 gcc/tree-vect-loop.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index bb021ccf382..ebdba65c55e 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -4730,10 +4730,14 @@ get_initial_def_for_reduction (loop_vec_info loop_vinfo,
         else
           def_for_init = build_int_cst (scalar_type, int_init_val);
 
-	if (adjustment_def || operand_equal_p (def_for_init, init_val, 0))
+	bool same_p = operand_equal_p (def_for_init, init_val, 0);
+	init_val = gimple_convert (&stmts, TREE_TYPE (vectype), init_val);
+	def_for_init = gimple_convert (&stmts, TREE_TYPE (vectype), def_for_init);
+
+	if (adjustment_def || same_p)
 	  {
 	    /* Option1: the first element is '0' or '1' as well.  */
-	    if (!operand_equal_p (def_for_init, init_val, 0))
+	    if (!same_p)
 	      *adjustment_def = init_val;
 	    init_def = gimple_build_vector_from_val (&stmts, vectype,
 						     def_for_init);
-- 
2.35.3

                 reply	other threads:[~2023-05-03 10:13 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=20230503101310.143791331F@imap2.suse-dmz.suse.de \
    --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).