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 PR36181: ICE with -ftree-parallelize-loops


Hi,

The bug happens when the loop to be parallelized contains a phi node
for a vector type:

vect_var_.32_20 = PHI <vect_var_.32_21(4), { 0, 0, 0, 0 }(9)>

This fix checks for phi nodes with vector types before triggering the
parallel code generation.

As automatic parallelization uses a static schedule, the iteration
domain has to be split in nbthreads parts.  This is done by expressing
all the scalar computations in the loop in function of a single
induction variable that goes from 0 to niter: canonicalize_loop_ivs.

To correctly parallelize vectorized code, one has to analyze the
scalar induction variables defined by these vector phi nodes, and
rewrite these in function of the single scalar induction variable of
the loop.  This change would be too invasive for 4.3, but feasible for
4.4.

The attached patch was regstrapped on trunk and amd64-linux.  I will
test the patch also on 4.3.  Okay for trunk and 4.3-branch?

Thanks,
Jan Sjodin and Sebastian Pop

-- 
AMD - GNU Tools
email: sebpop@gmail.com, jan.sjodin@amd.com
branch:trunk
revision:HEAD
configure:
make:
check:

2008-05-15  Sebastian Pop  <sebastian.pop@amd.com>
	    Jan Sjodin  <jan.sjodin@amd.com>

	* tree-parloops.c (loop_has_vector_phi_nodes): New.
	(parallelize_loops): Don't parallelize when the loop has vector
	phi nodes.

	* gcc.dg/tree-ssa/pr36181.c: New.

Index: gcc/testsuite/gcc.dg/tree-ssa/pr36181.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr36181.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr36181.c	(revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -ftree-parallelize-loops=2" } */
+
+int foo ()
+{
+  int i, sum = 0, data[1024];
+
+  for(i = 0; i<1024; i++)
+    sum += data[i];
+
+  return sum;
+}
+
Index: gcc/tree-parloops.c
===================================================================
--- gcc/tree-parloops.c	(revision 135425)
+++ gcc/tree-parloops.c	(working copy)
@@ -1797,6 +1797,27 @@ gen_parallel_loop (struct loop *loop, ht
   omp_expand_local (parallel_head);
 }
 
+/* Returns true when LOOP contains vector phi nodes.  */
+
+static bool
+loop_has_vector_phi_nodes (struct loop *loop)
+{
+  unsigned i;
+  basic_block *bbs = get_loop_body_in_dom_order (loop);
+  bool res = true;
+  tree phi;
+
+  for (i = 0; i < loop->num_nodes; i++)
+    for (phi = phi_nodes (bbs[i]); phi; phi = PHI_CHAIN (phi))
+      if (TREE_CODE (TREE_TYPE (PHI_RESULT (phi))) == VECTOR_TYPE)
+	goto end;
+
+  res = false;
+ end:
+  free (bbs);
+  return res;
+}
+
 /* Detect parallel loops and generate parallel code using libgomp
    primitives.  Returns true if some loop was parallelized, false
    otherwise.  */
@@ -1828,6 +1849,8 @@ parallelize_loops (void)
 	  /* And of course, the loop must be parallelizable.  */
 	  || !can_duplicate_loop_p (loop)
 	  || loop_has_blocks_with_irreducible_flag (loop)
+	  /* FIXME: the check for vector phi nodes could be removed.  */
+	  || loop_has_vector_phi_nodes (loop)
 	  || !loop_parallel_p (loop, reduction_list, &niter_desc))
 	continue;
 

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