diff mbox series

Fix PR91896

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

Commit Message

Richard Biener Sept. 25, 2019, 10:48 a.m. UTC
Removing operand swapping for reduction vectorization has enabled
more pattern recognition which in turn triggers a latent bug
in reduction vectorization.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2019-09-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/91896
	* tree-vect-loop.c (vectorizable_reduction): The single
	def-use cycle optimization cannot apply when there's more
	than one pattern stmt involved.

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

Patch

Index: gcc/testsuite/gcc.dg/torture/pr91896.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr91896.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr91896.c	(working copy)
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-ftree-vectorize" } */
+
+unsigned int
+zj (unsigned int et)
+{
+  signed char jr = 0;
+
+  do {
+    et *= 3;
+    jr += 2;
+  } while (jr >= 0);
+
+  if (et == (unsigned int) jr)
+    et = 0;
+
+  return et;
+}
Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c	(revision 276120)
+++ gcc/tree-vect-loop.c	(working copy)
@@ -6101,6 +6101,8 @@  vectorizable_reduction (stmt_vec_info st
       if (ncopies > 1
 	  && STMT_VINFO_RELEVANT (reduc_stmt_info) <= vect_used_only_live
 	  && (use_stmt_info = loop_vinfo->lookup_single_use (phi_result))
+	  && (!STMT_VINFO_IN_PATTERN_P (use_stmt_info)
+	      || !STMT_VINFO_PATTERN_DEF_SEQ (use_stmt_info))
 	  && vect_stmt_to_vectorize (use_stmt_info) == reduc_stmt_info)
 	single_defuse_cycle = true;
 
@@ -6868,6 +6870,8 @@  vectorizable_reduction (stmt_vec_info st
   if (ncopies > 1
       && (STMT_VINFO_RELEVANT (stmt_info) <= vect_used_only_live)
       && (use_stmt_info = loop_vinfo->lookup_single_use (reduc_phi_result))
+      && (!STMT_VINFO_IN_PATTERN_P (use_stmt_info)
+	  || !STMT_VINFO_PATTERN_DEF_SEQ (use_stmt_info))
       && vect_stmt_to_vectorize (use_stmt_info) == stmt_info)
     {
       single_defuse_cycle = true;