public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Vectorize assignments in loops with multiple types
@ 2009-11-30 12:21 Ira Rosen
  0 siblings, 0 replies; only message in thread
From: Ira Rosen @ 2009-11-30 12:21 UTC (permalink / raw)
  To: gcc-patches


Hi,

This patch adds the missing support of loops with multiple types in
vectorizable_assignment function. With this patch the initialization loops
of PR 42108 get vectorized (but this doesn't solve the performance
degradation problem).

Bootstrapped and tested on x86_64-suse-linux.
Committed revision 154794 (got an OK from Richard in the PR).

Thanks,
Ira

ChangeLog:

      * tree-vect-stmts.c (vectorizable_assignment): Support
      multiple types.

testsuite/ChangeLog:

      * gfortran.dg/vect/vect-7.f90: New test.


Index: tree-vect-stmts.c
===================================================================
--- tree-vect-stmts.c   (revision 154792)
+++ tree-vect-stmts.c   (working copy)
@@ -1809,10 +1809,12 @@ vectorizable_assignment (gimple stmt, gi
   enum vect_def_type dt[2] = {vect_unknown_def_type,
vect_unknown_def_type};
   int nunits = TYPE_VECTOR_SUBPARTS (vectype);
   int ncopies;
-  int i;
+  int i, j;
   VEC(tree,heap) *vec_oprnds = NULL;
   tree vop;
   bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_info);
+  gimple new_stmt = NULL;
+  stmt_vec_info prev_stmt_info = NULL;

   /* Multiple types in SLP are handled by creating the appropriate number
of
      vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in
@@ -1823,8 +1825,6 @@ vectorizable_assignment (gimple stmt, gi
     ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;

   gcc_assert (ncopies >= 1);
-  if (ncopies > 1)
-    return false; /* FORNOW */

   if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
     return false;
@@ -1870,20 +1870,35 @@ vectorizable_assignment (gimple stmt, gi
   vec_dest = vect_create_destination_var (scalar_dest, vectype);

   /* Handle use.  */
-  vect_get_vec_defs (op, NULL, stmt, &vec_oprnds, NULL, slp_node);
-
-  /* Arguments are ready. create the new vector stmt.  */
-  for (i = 0; VEC_iterate (tree, vec_oprnds, i, vop); i++)
+  for (j = 0; j < ncopies; j++)
     {
-      *vec_stmt = gimple_build_assign (vec_dest, vop);
-      new_temp = make_ssa_name (vec_dest, *vec_stmt);
-      gimple_assign_set_lhs (*vec_stmt, new_temp);
-      vect_finish_stmt_generation (stmt, *vec_stmt, gsi);
-      STMT_VINFO_VEC_STMT (stmt_info) = *vec_stmt;
+      /* Handle uses.  */
+      if (j == 0)
+        vect_get_vec_defs (op, NULL, stmt, &vec_oprnds, NULL, slp_node);
+      else
+        vect_get_vec_defs_for_stmt_copy (dt, &vec_oprnds, NULL);
+
+      /* Arguments are ready. create the new vector stmt.  */
+      for (i = 0; VEC_iterate (tree, vec_oprnds, i, vop); i++)
+       {
+         new_stmt = gimple_build_assign (vec_dest, vop);
+         new_temp = make_ssa_name (vec_dest, new_stmt);
+         gimple_assign_set_lhs (new_stmt, new_temp);
+         vect_finish_stmt_generation (stmt, new_stmt, gsi);
+         if (slp_node)
+           VEC_quick_push (gimple, SLP_TREE_VEC_STMTS (slp_node),
new_stmt);
+       }

       if (slp_node)
-       VEC_quick_push (gimple, SLP_TREE_VEC_STMTS (slp_node), *vec_stmt);
-   }
+        continue;
+
+      if (j == 0)
+        STMT_VINFO_VEC_STMT (stmt_info) = *vec_stmt = new_stmt;
+      else
+        STMT_VINFO_RELATED_STMT (prev_stmt_info) = new_stmt;
+
+      prev_stmt_info = vinfo_for_stmt (new_stmt);
+    }

   VEC_free (tree, heap, vec_oprnds);
   return true;
Index: testsuite/gfortran.dg/vect/vect-7.f90
===================================================================
--- testsuite/gfortran.dg/vect/vect-7.f90       (revision 0)
+++ testsuite/gfortran.dg/vect/vect-7.f90       (revision 0)
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! { dg-require-effective-target vect_double }
+
+subroutine foo (x,nnd)
+  dimension x(nnd)
+  integer i
+
+  do i=1,nnd
+    x(i) = 1.d0 + (1.d0*i)/nnd
+  end do
+
+end subroutine foo
+
+! { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target
vect_unpack } } }
+! { dg-final { cleanup-tree-dump "vect" } }
+

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-11-30 12:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-30 12:21 [patch] Vectorize assignments in loops with multiple types Ira Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).