2013-11-27 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Nov 2013 08:50:15 +0000 (08:50 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Nov 2013 08:50:15 +0000 (08:50 +0000)
PR tree-optimization/59288
* tree-vect-loop.c (get_initial_def_for_induction): Do not
re-analyze the PHI but use STMT_VINFO_LOOP_PHI_EVOLUTION_PART.

* gcc.dg/torture/pr59288.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205434 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 736b2c2..43383ff 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-27  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59288
+       * tree-vect-loop.c (get_initial_def_for_induction): Do not
+       re-analyze the PHI but use STMT_VINFO_LOOP_PHI_EVOLUTION_PART.
+
 2013-11-27  Marek Polacek  <polacek@redhat.com>
 
        * ubsan.c (ubsan_type_descriptor): If varpool_get_node returns NULL
index 61fe795..2edd80b 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-27  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/59288
+       * gcc.dg/torture/pr59288.c: New testcase.
+
 2013-11-27  Marek Polacek  <polacek@redhat.com>
 
        * c-c++-common/ubsan/undefined-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/pr59288.c b/gcc/testsuite/gcc.dg/torture/pr59288.c
new file mode 100644 (file)
index 0000000..8331e73
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+void
+baz (int *d)
+{
+  long int i, j, k;
+  for (i = 0, j = 0, k = 0; i < 512; i = (int) i + 1, j = (int) j + 1, k = (int) k + 3)
+    d[i] = j ^ (i * 3) ^ (2 * k + 2);
+}
index c91c2e1..50c9d9c 100644 (file)
@@ -3199,7 +3199,6 @@ get_initial_def_for_induction (gimple iv_phi)
   struct loop *iv_loop;
   basic_block new_bb;
   tree new_vec, vec_init, vec_step, t;
-  tree access_fn;
   tree new_var;
   tree new_name;
   gimple init_stmt, induction_phi, new_stmt;
@@ -3207,7 +3206,6 @@ get_initial_def_for_induction (gimple iv_phi)
   tree init_expr, step_expr;
   int vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
   int i;
-  bool ok;
   int ncopies;
   tree expr;
   stmt_vec_info phi_info = vinfo_for_stmt (iv_phi);
@@ -3236,13 +3234,12 @@ get_initial_def_for_induction (gimple iv_phi)
   latch_e = loop_latch_edge (iv_loop);
   loop_arg = PHI_ARG_DEF_FROM_EDGE (iv_phi, latch_e);
 
-  access_fn = analyze_scalar_evolution (iv_loop, PHI_RESULT (iv_phi));
-  gcc_assert (access_fn);
-  STRIP_NOPS (access_fn);
-  ok = vect_is_simple_iv_evolution (iv_loop->num, access_fn,
-                                    &init_expr, &step_expr);
-  gcc_assert (ok);
+  step_expr = STMT_VINFO_LOOP_PHI_EVOLUTION_PART (phi_info);
+  gcc_assert (step_expr != NULL_TREE);
+
   pe = loop_preheader_edge (iv_loop);
+  init_expr = PHI_ARG_DEF_FROM_EDGE (iv_phi,
+                                    loop_preheader_edge (iv_loop));
 
   vectype = get_vectype_for_scalar_type (TREE_TYPE (init_expr));
   resvectype = get_vectype_for_scalar_type (TREE_TYPE (PHI_RESULT (iv_phi)));
@@ -3253,6 +3250,16 @@ get_initial_def_for_induction (gimple iv_phi)
   gcc_assert (phi_info);
   gcc_assert (ncopies >= 1);
 
+  /* Convert the step to the desired type.  */
+  step_expr = force_gimple_operand (fold_convert (TREE_TYPE (vectype),
+                                                 step_expr),
+                                   &stmts, true, NULL_TREE);
+  if (stmts)
+    {
+      new_bb = gsi_insert_seq_on_edge_immediate (pe, stmts);
+      gcc_assert (!new_bb);
+    }
+
   /* Find the first insertion point in the BB.  */
   si = gsi_after_labels (bb);
 
@@ -3262,9 +3269,7 @@ get_initial_def_for_induction (gimple iv_phi)
       /* iv_loop is nested in the loop to be vectorized.  init_expr had already
         been created during vectorization of previous stmts.  We obtain it
         from the STMT_VINFO_VEC_STMT of the defining stmt.  */
-      tree iv_def = PHI_ARG_DEF_FROM_EDGE (iv_phi,
-                                           loop_preheader_edge (iv_loop));
-      vec_init = vect_get_vec_def_for_operand (iv_def, iv_phi, NULL);
+      vec_init = vect_get_vec_def_for_operand (init_expr, iv_phi, NULL);
       /* If the initial value is not of proper type, convert it.  */
       if (!useless_type_conversion_p (vectype, TREE_TYPE (vec_init)))
        {