re PR tree-optimization/69720 (wrong code at -O3 on x86_64-linux-gnu)
authorRichard Biener <rguenther@suse.de>
Mon, 29 Feb 2016 08:45:17 +0000 (08:45 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 29 Feb 2016 08:45:17 +0000 (08:45 +0000)
2016-02-29  Richard Biener  <rguenther@suse.de>

PR tree-optimization/69720
* tree-vect-loop.c (get_initial_def_for_reduction): Avoid
the adjustment_def path for possibly vectorized defs.
(vect_create_epilog_for_reduction): Handle vectorized initial
defs properly.

* gcc.dg/vect/vect-outer-pr69720.c: New testcase.

From-SVN: r233803

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-outer-pr69720.c [new file with mode: 0644]
gcc/tree-vect-loop.c

index 4db03b62e8346b0c49873b3ccb0d91d6b5d677e2..772fc3b7582c883224c81a40fc1565c52721e822 100644 (file)
@@ -1,3 +1,11 @@
+2016-02-29  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/69720
+       * tree-vect-loop.c (get_initial_def_for_reduction): Avoid
+       the adjustment_def path for possibly vectorized defs.
+       (vect_create_epilog_for_reduction): Handle vectorized initial
+       defs properly.
+
 2016-02-28  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/i386/cygming.h (STACK_REALIGN_DEFAULT): Define.
index 3a56e66ac8894e037c5f12d656ca70cba5a455f2..8347c677cd439ec32109db06b2613a4240acbb43 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-29  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/69720
+       * gcc.dg/vect/vect-outer-pr69720.c: New testcase.
+
 2016-02-28  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/68147
diff --git a/gcc/testsuite/gcc.dg/vect/vect-outer-pr69720.c b/gcc/testsuite/gcc.dg/vect/vect-outer-pr69720.c
new file mode 100644 (file)
index 0000000..bcfcc6d
--- /dev/null
@@ -0,0 +1,28 @@
+extern void abort (void);
+
+int a[128];
+double b[128] = { 1., 2., 3., 4. };
+
+void __attribute__((noinline)) foo()
+{
+  int i;
+  for (i = 0; i < 128; ++i)
+    {
+      double tem1 = b[i];
+      for (int j = 0; j < 32; ++j)
+       tem1 += 1;
+      b[i] = tem1;
+      a[i] = i;
+    }
+}
+
+int main()
+{
+  foo ();
+  if (b[0] != 33. || b[1] != 34.
+      || b[2] != 35. || b[3] != 36.)
+    abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "OUTER LOOP VECTORIZED" 1 "vect" { target { vect_double && vect_int } } } } */
index 8c346697458bdf951d299d9006d72b2e35dc3c3d..627ff1c5cf38fce4c285ee0c49a842fe0c8339ba 100644 (file)
@@ -4110,6 +4110,15 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
       return vect_create_destination_var (init_val, vectype);
     }
 
+  /* In case of a nested reduction do not use an adjustment def as
+     that case is not supported by the epilogue generation correctly
+     if ncopies is not one.  */
+  if (adjustment_def && nested_in_vect_loop)
+    {
+      *adjustment_def = NULL;
+      return vect_get_vec_def_for_operand (init_val, stmt);
+    }
+
   switch (code)
     {
       case WIDEN_SUM_EXPR:
@@ -4124,12 +4133,7 @@ get_initial_def_for_reduction (gimple *stmt, tree init_val,
         /* ADJUSMENT_DEF is NULL when called from
            vect_create_epilog_for_reduction to vectorize double reduction.  */
         if (adjustment_def)
-          {
-            if (nested_in_vect_loop)
-              *adjustment_def = vect_get_vec_def_for_operand (init_val, stmt);
-            else
-              *adjustment_def = init_val;
-          }
+         *adjustment_def = init_val;
 
         if (code == MULT_EXPR)
           {
@@ -4341,6 +4345,7 @@ vect_create_epilog_for_reduction (vec<tree> vect_defs, gimple *stmt,
      (in case of SLP, do it for all the phis). */
 
   /* Get the loop-entry arguments.  */
+  enum vect_def_type initial_def_dt = vect_unknown_def_type;
   if (slp_node)
     vect_get_vec_defs (reduction_op, NULL_TREE, stmt, &vec_initial_defs,
                        NULL, slp_node, reduc_index);
@@ -4351,9 +4356,10 @@ vect_create_epilog_for_reduction (vec<tree> vect_defs, gimple *stmt,
       gimple *def_stmt = SSA_NAME_DEF_STMT (reduction_op);
       initial_def = PHI_ARG_DEF_FROM_EDGE (def_stmt,
                                           loop_preheader_edge (loop));
-      vec_initial_defs.create (1);
+      vect_is_simple_use (initial_def, loop_vinfo, &def_stmt, &initial_def_dt);
       vec_initial_def = get_initial_def_for_reduction (stmt, initial_def,
                                                       &adjustment_def);
+      vec_initial_defs.create (1);
       vec_initial_defs.quick_push (vec_initial_def);
     }
 
@@ -4368,6 +4374,15 @@ vect_create_epilog_for_reduction (vec<tree> vect_defs, gimple *stmt,
       def = vect_defs[i];
       for (j = 0; j < ncopies; j++)
         {
+         if (j != 0)
+           {
+             phi = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (phi));
+             if (nested_in_vect_loop)
+               vec_init_def
+                 = vect_get_vec_def_for_stmt_copy (initial_def_dt,
+                                                   vec_init_def);
+           }
+
          /* Set the loop-entry arg of the reduction-phi.  */
 
          if (STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info)
@@ -4404,8 +4419,6 @@ vect_create_epilog_for_reduction (vec<tree> vect_defs, gimple *stmt,
               dump_gimple_stmt (MSG_NOTE, TDF_SLIM, SSA_NAME_DEF_STMT (def), 0);
               dump_printf (MSG_NOTE, "\n");
             }
-
-          phi = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (phi));
         }
     }