diff mbox series

Fix PR92371

Message ID nycvar.YFH.7.76.1911051710470.5566@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR92371 | expand

Commit Message

Richard Biener Nov. 5, 2019, 4:11 p.m. UTC
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2019-11-05  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/92371
	* tree-vect-loop.c (vectorizable_reduction): Set STMT_VINFO_REDUC_DEF
	on the original stmt of live stmts in the chain.
	(vectorizable_live_operation): Look at the original stmt when
	checking STMT_VINFO_REDUC_DEF.

	* gcc.dg/torture/pr92371.c: New testcase.
diff mbox series

Patch

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c	(revision 277849)
+++ gcc/tree-vect-loop.c	(working copy)
@@ -5836,21 +5836,22 @@  vectorizable_reduction (stmt_vec_info st
   while (reduc_def != PHI_RESULT (reduc_def_phi))
     {
       stmt_vec_info def = loop_vinfo->lookup_def (reduc_def);
-      def = vect_stmt_to_vectorize (def);
-      if (STMT_VINFO_REDUC_IDX (def) == -1)
+      stmt_vec_info vdef = vect_stmt_to_vectorize (def);
+      if (STMT_VINFO_REDUC_IDX (vdef) == -1)
 	{
 	  if (dump_enabled_p ())
 	    dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
 			     "reduction chain broken by patterns.\n");
 	  return false;
 	}
-      if (!REDUC_GROUP_FIRST_ELEMENT (def))
+      if (!REDUC_GROUP_FIRST_ELEMENT (vdef))
 	only_slp_reduc_chain = false;
       /* ???  For epilogue generation live members of the chain need
-         to point back to the PHI for info_for_reduction to work.  */
-      if (STMT_VINFO_LIVE_P (def))
+         to point back to the PHI via their original stmt for
+	 info_for_reduction to work.  */
+      if (STMT_VINFO_LIVE_P (vdef))
 	STMT_VINFO_REDUC_DEF (def) = phi_info;
-      reduc_def = gimple_op (def->stmt, 1 + STMT_VINFO_REDUC_IDX (def));
+      reduc_def = gimple_op (vdef->stmt, 1 + STMT_VINFO_REDUC_IDX (vdef));
       reduc_chain_length++;
     }
 
@@ -7554,7 +7555,7 @@  vectorizable_live_operation (stmt_vec_in
   /* If a stmt of a reduction is live, vectorize it via
      vect_create_epilog_for_reduction.  vectorizable_reduction assessed
      validity so just trigger the transform here.  */
-  if (STMT_VINFO_REDUC_DEF (stmt_info))
+  if (STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)))
     {
       if (!vec_stmt_p)
 	return true;