public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][GCC 11] tree-optimization/109473 - fix type mismatch in reduction vectorization
@ 2023-05-03 10:13 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-05-03 10:13 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-03 10:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 10:13 [PATCH][GCC 11] tree-optimization/109473 - fix type mismatch in reduction vectorization Richard Biener

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).