This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix various vectorizer regressions my recent patch caused (PR middle-end/51590)


Hi!

When I've switched STMT_VINFO_PATTERN_DEF_STMT into
a gimple_seq STMT_VINFO_PATTERN_DEF_SEQ, I've been using
gimplify_seq_add_stmt and/or gimple_seq_alloc_with_stmt
to populate the sequences.  While the former is right
for this case and doesn't mark the stmt being added for updating,
the latter calls gimple_seq_add_stmt which does what
gimplify_seq_add_stmt does, but additionally marks the stmt
for updating.  As I'm using the gimple_seq sequences for
the pattern defs just as containers for multiple statements,
it is undesirable to update those.

The following patch fixes it, bootstrapped/regtested on x86_64-linux
and i686-linux.  Richard had on IRC issues with the
gimplify_seq_add_stmt name, I'll send a patch for that as a follow-up.
Ok for trunk?

2011-12-19  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/51590
	PR tree-optimization/51606
	* tree-vect-patterns.c (append_pattern_def_seq, new_pattern_def_seq):
	New inline functions.
	(vect_recog_over_widening_pattern,
	vect_recog_vector_vector_shift_pattern,
	vect_recog_sdivmod_pow2_pattern, vect_recog_mixed_size_cond_pattern,
	adjust_bool_pattern_cast, vect_recog_bool_pattern): Use them.

	* gcc.dg/vect/pr51590.c: New test.

--- gcc/tree-vect-patterns.c.jj	2011-12-16 08:37:45.000000000 +0100
+++ gcc/tree-vect-patterns.c	2011-12-19 10:18:34.443847675 +0100
@@ -70,6 +70,19 @@ static vect_recog_func_ptr vect_vect_rec
 	vect_recog_mixed_size_cond_pattern,
 	vect_recog_bool_pattern};
 
+static inline void
+append_pattern_def_seq (stmt_vec_info stmt_info, gimple stmt)
+{
+  gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_info), stmt);
+}
+
+static inline void
+new_pattern_def_seq (stmt_vec_info stmt_info, gimple stmt)
+{
+  STMT_VINFO_PATTERN_DEF_SEQ (stmt_info) = NULL;
+  append_pattern_def_seq (stmt_info, stmt);
+}
+
 /* Function widened_name_p
 
    Check whether NAME, an ssa-name used in USE_STMT,
@@ -1146,8 +1159,7 @@ vect_recog_over_widening_pattern (VEC (g
 	= gimple_build_assign_with_ops (gimple_assign_rhs_code (stmt), var,
 					op0, op1);
       STMT_VINFO_RELATED_STMT (vinfo_for_stmt (stmt)) = pattern_stmt;
-      STMT_VINFO_PATTERN_DEF_SEQ (vinfo_for_stmt (stmt))
-	= gimple_seq_alloc_with_stmt (new_def_stmt);
+      new_pattern_def_seq (vinfo_for_stmt (stmt), new_def_stmt);
 
       if (vect_print_dump_info (REPORT_DETAILS))
         {
@@ -1559,8 +1571,7 @@ vect_recog_vector_vector_shift_pattern (
       def = vect_recog_temp_ssa_var (TREE_TYPE (oprnd0), NULL);
       def_stmt = gimple_build_assign_with_ops (NOP_EXPR, def, oprnd1,
 					       NULL_TREE);
-      STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo)
-	= gimple_seq_alloc_with_stmt (def_stmt);
+      new_pattern_def_seq (stmt_vinfo, def_stmt);
     }
 
   /* Pattern detected.  */
@@ -1688,14 +1699,12 @@ vect_recog_sdivmod_pow2_pattern (VEC (gi
 						      build_int_cst (itype,
 								     1)),
 					 build_int_cst (itype, 0));
-      STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo)
-	= gimple_seq_alloc_with_stmt (def_stmt);
+      new_pattern_def_seq (stmt_vinfo, def_stmt);
       var = vect_recog_temp_ssa_var (itype, NULL);
       def_stmt
 	= gimple_build_assign_with_ops (PLUS_EXPR, var, oprnd0,
 					gimple_assign_lhs (def_stmt));
-      gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-			     def_stmt);
+      append_pattern_def_seq (stmt_vinfo, def_stmt);
 
       pattern_stmt
 	= gimple_build_assign_with_ops (RSHIFT_EXPR,
@@ -1715,8 +1724,7 @@ vect_recog_sdivmod_pow2_pattern (VEC (gi
 	    = gimple_build_assign_with_ops3 (COND_EXPR, signmask, cond,
 					     build_int_cst (itype, 1),
 					     build_int_cst (itype, 0));
-	  gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-				 def_stmt);
+	  append_pattern_def_seq (stmt_vinfo, def_stmt);
 	}
       else
 	{
@@ -1736,8 +1744,7 @@ vect_recog_sdivmod_pow2_pattern (VEC (gi
 	  def_stmt_vinfo = new_stmt_vec_info (def_stmt, loop_vinfo, NULL);
 	  set_vinfo_for_stmt (def_stmt, def_stmt_vinfo);
 	  STMT_VINFO_VECTYPE (def_stmt_vinfo) = vecutype;
-	  gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-				 def_stmt);
+	  append_pattern_def_seq (stmt_vinfo, def_stmt);
 	  var = vect_recog_temp_ssa_var (utype, NULL);
 	  def_stmt
 	    = gimple_build_assign_with_ops (RSHIFT_EXPR, var,
@@ -1746,21 +1753,18 @@ vect_recog_sdivmod_pow2_pattern (VEC (gi
 	  def_stmt_vinfo = new_stmt_vec_info (def_stmt, loop_vinfo, NULL);
 	  set_vinfo_for_stmt (def_stmt, def_stmt_vinfo);
 	  STMT_VINFO_VECTYPE (def_stmt_vinfo) = vecutype;
-	  gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-				 def_stmt);
+	  append_pattern_def_seq (stmt_vinfo, def_stmt);
 	  signmask = vect_recog_temp_ssa_var (itype, NULL);
 	  def_stmt
 	    = gimple_build_assign_with_ops (NOP_EXPR, signmask, var,
 					    NULL_TREE);
-	  gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-				 def_stmt);
+	  append_pattern_def_seq (stmt_vinfo, def_stmt);
 	}
       def_stmt
 	= gimple_build_assign_with_ops (PLUS_EXPR,
 					vect_recog_temp_ssa_var (itype, NULL),
 					oprnd0, signmask);
-      gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-			     def_stmt);
+      append_pattern_def_seq (stmt_vinfo, def_stmt);
       def_stmt
 	= gimple_build_assign_with_ops (BIT_AND_EXPR,
 					vect_recog_temp_ssa_var (itype, NULL),
@@ -1769,8 +1773,7 @@ vect_recog_sdivmod_pow2_pattern (VEC (gi
 						     oprnd1,
 						     build_int_cst (itype,
 								    1)));
-      gimplify_seq_add_stmt (&STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo),
-			     def_stmt);
+      append_pattern_def_seq (stmt_vinfo, def_stmt);
 
       pattern_stmt
 	= gimple_build_assign_with_ops (MINUS_EXPR,
@@ -1896,8 +1899,7 @@ vect_recog_mixed_size_cond_pattern (VEC
 				    vect_recog_temp_ssa_var (type, NULL),
 				    gimple_assign_lhs (def_stmt), NULL_TREE);
 
-  STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo)
-    = gimple_seq_alloc_with_stmt (def_stmt);
+  new_pattern_def_seq (stmt_vinfo, def_stmt);
   def_stmt_info = new_stmt_vec_info (def_stmt, loop_vinfo, NULL);
   set_vinfo_for_stmt (def_stmt, def_stmt_info);
   STMT_VINFO_VECTYPE (def_stmt_info) = vecitype;
@@ -1994,8 +1996,7 @@ adjust_bool_pattern_cast (tree type, tre
 
   gcc_assert (!STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo));
   pattern_stmt = STMT_VINFO_RELATED_STMT (stmt_vinfo);
-  STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo)
-    = gimple_seq_alloc_with_stmt (pattern_stmt);
+  new_pattern_def_seq (stmt_vinfo, pattern_stmt);
   cast_stmt
     = gimple_build_assign_with_ops (NOP_EXPR,
 				    vect_recog_temp_ssa_var (type, NULL),
@@ -2304,8 +2305,7 @@ vect_recog_bool_pattern (VEC (gimple, he
 	  tree rhs2 = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
 	  gimple cast_stmt
 	    = gimple_build_assign_with_ops (NOP_EXPR, rhs2, rhs, NULL_TREE);
-	  STMT_VINFO_PATTERN_DEF_SEQ (stmt_vinfo)
-	    = gimple_seq_alloc_with_stmt (cast_stmt);
+	  new_pattern_def_seq (stmt_vinfo, cast_stmt);
 	  rhs = rhs2;
 	}
       pattern_stmt
--- gcc/testsuite/gcc.dg/vect/pr51590.c.jj	2011-12-19 10:16:49.615452251 +0100
+++ gcc/testsuite/gcc.dg/vect/pr51590.c	2011-12-19 10:16:42.000000000 +0100
@@ -0,0 +1,35 @@
+/* PR middle-end/51590 */
+/* { dg-do compile } */
+
+struct S { long a, b; };
+
+extern void baz (char *);
+
+static void
+bar (struct S *x)
+{
+  char c[8];
+  int i;
+
+  for (i = 0; i < 8; i++)
+    c[i] = x->a >> ((7 - i) * 8);
+
+  baz (c);
+}
+
+void
+foo (const char *x, struct S *y)
+{
+  struct S d = *y;
+  int i;
+
+  for (i = 0; *x; x++)
+    i++;
+
+  if (i != 1)
+    return;
+
+  bar (&d);
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]