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][graphite] Fix h264ref and dealII


Hi,

after the recent changes to the graphite branch, the regression testers
failed on two spec2006 benchmarks.  The attached patches fix these
errors.  Committed to the graphite branch for further testing.

Sebastian Pop
--
AMD / Open Source Compiler Engineering / GNU Tools
From c92a5edb7770ca8d3b8c0789b524bbc1e121d31a Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Wed, 16 Jun 2010 18:15:47 -0500
Subject: [PATCH 1/6] Add more debug counter guards.

2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite.c (graphite_transform_loops): Add two more dbg_cnt calls.
---
 gcc/ChangeLog.graphite |    4 ++++
 gcc/graphite.c         |   13 ++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index fa75c61..b46773a 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,3 +1,7 @@
+2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
+
+	* graphite.c (graphite_transform_loops): Add two more dbg_cnt calls.
+
 2010-06-15  Sebastian Pop  <sebastian.pop@amd.com>
 
 	* passes.c (init_optimization_passes): Add pass_graphite.
diff --git a/gcc/graphite.c b/gcc/graphite.c
index 51bf800..5b3b6aa 100644
--- a/gcc/graphite.c
+++ b/gcc/graphite.c
@@ -272,13 +272,16 @@ graphite_transform_loops (void)
   sbitmap_zero (reductions);
 
   for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
-    rewrite_commutative_reductions_out_of_ssa (SCOP_REGION (scop), reductions);
+    if (dbg_cnt (graphite_scop))
+      rewrite_commutative_reductions_out_of_ssa (SCOP_REGION (scop),
+						 reductions);
 
   for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
-    {
-      rewrite_reductions_out_of_ssa (scop);
-      build_scop_bbs (scop, reductions);
-    }
+    if (dbg_cnt (graphite_scop))
+      {
+	rewrite_reductions_out_of_ssa (scop);
+	build_scop_bbs (scop, reductions);
+      }
 
   sbitmap_free (reductions);
 
-- 
1.7.0.4

From 620370c78c6129caa801d7961f5bce173efd67b8 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Thu, 17 Jun 2010 12:54:47 -0500
Subject: [PATCH 2/6] Split rewrite_cross_bb_scalar_deps_out_of_ssa out from rewrite_reductions_out_of_ssa.

2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-sese-to-poly.c (rewrite_cross_bb_scalar_deps_out_of_ssa):
	Split out of rewrite_reductions_out_of_ssa.
	* graphite-sese-to-poly.h (rewrite_cross_bb_scalar_deps_out_of_ssa):
	Declared.
	* graphite.c (graphite_transform_loops): Call it.
---
 gcc/ChangeLog.graphite      |    8 ++++++++
 gcc/graphite-sese-to-poly.c |   11 +++++++++++
 gcc/graphite-sese-to-poly.h |    1 +
 gcc/graphite.c              |    1 +
 4 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index b46773a..5bb56a0 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,13 @@
 2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (rewrite_cross_bb_scalar_deps_out_of_ssa):
+	Split out of rewrite_reductions_out_of_ssa.
+	* graphite-sese-to-poly.h (rewrite_cross_bb_scalar_deps_out_of_ssa):
+	Declared.
+	* graphite.c (graphite_transform_loops): Call it.
+
+2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite.c (graphite_transform_loops): Add two more dbg_cnt calls.
 
 2010-06-15  Sebastian Pop  <sebastian.pop@amd.com>
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 57967e5..0f96d19 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2424,6 +2424,17 @@ rewrite_reductions_out_of_ssa (scop_p scop)
 #ifdef ENABLE_CHECKING
   verify_loop_closed_ssa (true);
 #endif
+}
+
+
+/* Rewrite out of SSA all the reduction phi nodes of SCOP.  */
+
+void
+rewrite_cross_bb_scalar_deps_out_of_ssa (scop_p scop)
+{
+  basic_block bb;
+  gimple_stmt_iterator psi;
+  sese region = SCOP_REGION (scop);
 
   FOR_EACH_BB (bb)
     if (bb_in_sese_p (bb, region))
diff --git a/gcc/graphite-sese-to-poly.h b/gcc/graphite-sese-to-poly.h
index 2e0cc08..558a283 100644
--- a/gcc/graphite-sese-to-poly.h
+++ b/gcc/graphite-sese-to-poly.h
@@ -32,6 +32,7 @@ void build_poly_scop (scop_p);
 void check_poly_representation (scop_p);
 void rewrite_commutative_reductions_out_of_ssa (sese, sbitmap);
 void rewrite_reductions_out_of_ssa (scop_p);
+void rewrite_cross_bb_scalar_deps_out_of_ssa (scop_p);
 void build_scop_bbs (scop_p, sbitmap);
 
 #endif
diff --git a/gcc/graphite.c b/gcc/graphite.c
index 5b3b6aa..4bb4344 100644
--- a/gcc/graphite.c
+++ b/gcc/graphite.c
@@ -280,6 +280,7 @@ graphite_transform_loops (void)
     if (dbg_cnt (graphite_scop))
       {
 	rewrite_reductions_out_of_ssa (scop);
+	rewrite_cross_bb_scalar_deps_out_of_ssa (scop);
 	build_scop_bbs (scop, reductions);
       }
 
-- 
1.7.0.4

From ebba51c32c700d9b9ac8fdd6e7042d4f8bec008e Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Thu, 17 Jun 2010 17:34:53 -0500
Subject: [PATCH 3/6] Always insert out of SSA copies on edges except for loop->latch.

2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-sese-to-poly.c (rewrite_phi_out_of_ssa): Always insert out
	of SSA copies on edges except for loop->latch.
---
 gcc/ChangeLog.graphite      |    5 ++++
 gcc/graphite-sese-to-poly.c |   54 ++++---------------------------------------
 2 files changed, 10 insertions(+), 49 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index 5bb56a0..e0e0152 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,10 @@
 2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (rewrite_phi_out_of_ssa): Always insert out
+	of SSA copies on edges except for loop->latch.
+
+2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite-sese-to-poly.c (rewrite_cross_bb_scalar_deps_out_of_ssa):
 	Split out of rewrite_reductions_out_of_ssa.
 	* graphite-sese-to-poly.h (rewrite_cross_bb_scalar_deps_out_of_ssa):
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 0f96d19..2a34376 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2245,58 +2245,14 @@ rewrite_phi_out_of_ssa (gimple_stmt_iterator *psi)
   for (i = 0; i < gimple_phi_num_args (phi); i++)
     {
       tree arg = gimple_phi_arg_def (phi, i);
+      edge e = gimple_phi_arg_edge (phi, i);
 
-      /* Try to avoid the insertion on edges as much as possible: this
-	 would avoid the insertion of code on loop latch edges, making
-	 the pattern matching of the vectorizer happy, or it would
-	 avoid the insertion of useless basic blocks.  Note that it is
-	 incorrect to insert out of SSA copies close by their
-	 definition when they are more than two loop levels apart:
-	 for example, starting from a double nested loop
-
-	 | a = ...
-	 | loop_1
-	 |  loop_2
-	 |    b = phi (a, c)
-	 |    c = ...
-	 |  end_2
-	 | end_1
-
-	 the following transform is incorrect
-
-	 | a = ...
-	 | Red[0] = a
-	 | loop_1
-	 |  loop_2
-	 |    b = Red[0]
-	 |    c = ...
-	 |    Red[0] = c
-	 |  end_2
-	 | end_1
-
-	 whereas inserting the copy on the incoming edge is correct
-
-	 | a = ...
-	 | loop_1
-	 |  Red[0] = a
-	 |  loop_2
-	 |    b = Red[0]
-	 |    c = ...
-	 |    Red[0] = c
-	 |  end_2
-	 | end_1
-      */
-      if (TREE_CODE (arg) == SSA_NAME
-	  && is_gimple_reg (arg)
-	  && gimple_bb (SSA_NAME_DEF_STMT (arg))
-	  && (flow_bb_inside_loop_p (bb->loop_father,
-				     gimple_bb (SSA_NAME_DEF_STMT (arg)))
-	      || flow_bb_inside_loop_p (loop_outer (bb->loop_father),
-					gimple_bb (SSA_NAME_DEF_STMT (arg)))))
+      /* Avoid the insertion of code in the loop latch to please the
+	 pattern matching of the vectorizer.  */
+      if (e->src == bb->loop_father->latch)
 	insert_out_of_ssa_copy (zero_dim_array, arg, SSA_NAME_DEF_STMT (arg));
       else
-	insert_out_of_ssa_copy_on_edge (gimple_phi_arg_edge (phi, i),
-					zero_dim_array, arg);
+	insert_out_of_ssa_copy_on_edge (e, zero_dim_array, arg);
     }
 
   var = force_gimple_operand (zero_dim_array, &stmts, true, NULL_TREE);
-- 
1.7.0.4

From 5495c268e6284e6a1951fbe6b828be923966071e Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Thu, 17 Jun 2010 17:35:26 -0500
Subject: [PATCH 4/6] Fix testcase: call abort.

2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>

	* gcc.dg/graphite/run-id-2.c: Call abort.
---
 gcc/ChangeLog.graphite                   |    4 ++++
 gcc/testsuite/gcc.dg/graphite/run-id-2.c |   12 ++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index e0e0152..9ac373e 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,9 @@
 2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* gcc.dg/graphite/run-id-2.c: Call abort.
+
+2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite-sese-to-poly.c (rewrite_phi_out_of_ssa): Always insert out
 	of SSA copies on edges except for loop->latch.
 
diff --git a/gcc/testsuite/gcc.dg/graphite/run-id-2.c b/gcc/testsuite/gcc.dg/graphite/run-id-2.c
index 0fd5efd..4a23616 100644
--- a/gcc/testsuite/gcc.dg/graphite/run-id-2.c
+++ b/gcc/testsuite/gcc.dg/graphite/run-id-2.c
@@ -19,9 +19,17 @@ static int __attribute__((noinline)) bar(int n)
   return c;
 }
 
+extern void abort ();
+
 int main()
 {
-  return
-   foo(0) != 0 || foo(1) != 1 || bar(0) != 0 || bar(1) != 2 || bar(2) != 5;
+  if (foo(0) != 0
+      || foo(1) != 1
+      || bar(0) != 0
+      || bar(1) != 2
+      || bar(2) != 5)
+    abort ();
+
+  return 0;
 }
 
-- 
1.7.0.4

From 80d07ae6fe4e99d65a703a3980d3b9ad60a1604d Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Wed, 23 Jun 2010 10:56:31 -0500
Subject: [PATCH 5/6] Early return in rewrite_commutative_reductions_out_of_ssa when flag_associative_math is not set.

2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-sese-to-poly.c (rewrite_commutative_reductions_out_of_ssa):
	Early return in when flag_associative_math is not set.
---
 gcc/ChangeLog.graphite      |    5 +++++
 gcc/graphite-sese-to-poly.c |    3 +++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index 9ac373e..5d142df 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,10 @@
 2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (rewrite_commutative_reductions_out_of_ssa):
+	Early return in when flag_associative_math is not set.
+
+2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* gcc.dg/graphite/run-id-2.c: Call abort.
 
 2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 2a34376..1f676e7 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2828,6 +2828,9 @@ rewrite_commutative_reductions_out_of_ssa (sese region, sbitmap reductions)
   loop_iterator li;
   loop_p loop;
 
+  if (!flag_associative_math)
+    return;
+
   FOR_EACH_LOOP (li, loop, 0)
     if (loop_in_sese_p (loop, region))
       rewrite_commutative_reductions_out_of_ssa_loop (loop, reductions);
-- 
1.7.0.4

From 5a744fb4155f73ebbcc0ce7c88e23821793c61b3 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Wed, 23 Jun 2010 15:29:19 -0500
Subject: [PATCH 6/6] Run rewrite_cross_bb_phi_deps before rewrite_cross_bb_scalar_deps.

2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>

	* graphite-sese-to-poly.c (rewrite_reductions_out_of_ssa): Moved up.
	(rewrite_cross_bb_phi_deps): Split out of rewrite_cross_bb_scalar_deps.
	(rewrite_cross_bb_scalar_deps_out_of_ssa): Run rewrite_cross_bb_phi_deps
	before rewrite_cross_bb_scalar_deps.
---
 gcc/ChangeLog.graphite      |    7 +++
 gcc/graphite-sese-to-poly.c |   96 ++++++++++++++++++++++++++++---------------
 2 files changed, 70 insertions(+), 33 deletions(-)

diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index 5d142df..423fae9 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,12 @@
 2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (rewrite_reductions_out_of_ssa): Moved up.
+	(rewrite_cross_bb_phi_deps): Split out of rewrite_cross_bb_scalar_deps.
+	(rewrite_cross_bb_scalar_deps_out_of_ssa): Run rewrite_cross_bb_phi_deps
+	before rewrite_cross_bb_scalar_deps.
+
+2010-06-23  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite-sese-to-poly.c (rewrite_commutative_reductions_out_of_ssa):
 	Early return in when flag_associative_math is not set.
 
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 1f676e7..d0db7fa 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2271,6 +2271,31 @@ rewrite_phi_out_of_ssa (gimple_stmt_iterator *psi)
   gsi_insert_seq_before (&gsi, stmts, GSI_NEW_STMT);
 }
 
+/* Rewrite out of SSA all the reduction phi nodes of SCOP.  */
+
+void
+rewrite_reductions_out_of_ssa (scop_p scop)
+{
+  basic_block bb;
+  gimple_stmt_iterator psi;
+  sese region = SCOP_REGION (scop);
+
+  FOR_EACH_BB (bb)
+    if (bb_in_sese_p (bb, region))
+      for (psi = gsi_start_phis (bb); !gsi_end_p (psi);)
+	{
+	  if (scalar_close_phi_node_p (gsi_stmt (psi)))
+	    rewrite_close_phi_out_of_ssa (&psi);
+	  else if (reduction_phi_p (region, &psi))
+	    rewrite_phi_out_of_ssa (&psi);
+	}
+
+  update_ssa (TODO_update_ssa);
+#ifdef ENABLE_CHECKING
+  verify_loop_closed_ssa (true);
+#endif
+}
+
 /* Return true when DEF can be analyzed in REGION by the scalar
    evolution analyzer.  */
 
@@ -2313,16 +2338,16 @@ rewrite_cross_bb_scalar_dependence (tree zero_dim_array, tree def, gimple use_st
 }
 
 /* Rewrite the scalar dependences crossing the boundary of the BB
-   containing STMT with an array.  */
+   containing STMT with an array.  GSI points to a definition that is
+   used in a PHI node.  */
 
 static void
-rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
+rewrite_cross_bb_phi_deps (sese region, gimple_stmt_iterator gsi)
 {
-  gimple stmt = gsi_stmt (*gsi);
+  gimple stmt = gsi_stmt (gsi);
   imm_use_iterator imm_iter;
   tree def;
   basic_block def_bb;
-  tree zero_dim_array = NULL_TREE;
   gimple use_stmt;
 
   if (gimple_code (stmt) != GIMPLE_ASSIGN)
@@ -2341,9 +2366,37 @@ rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
 	gimple_stmt_iterator si = gsi_for_stmt (use_stmt);
 	rewrite_phi_out_of_ssa (&si);
       }
-    else if (def_bb != gimple_bb (use_stmt)
-	     && !is_gimple_debug (use_stmt))
+}
+
+/* Rewrite the scalar dependences crossing the boundary of the BB
+   containing STMT with an array.  */
+
+static void
+rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
+{
+  gimple stmt = gsi_stmt (*gsi);
+  imm_use_iterator imm_iter;
+  tree def;
+  basic_block def_bb;
+  tree zero_dim_array = NULL_TREE;
+  gimple use_stmt;
+
+  if (gimple_code (stmt) != GIMPLE_ASSIGN)
+    return;
+
+  def = gimple_assign_lhs (stmt);
+  if (!is_gimple_reg (def)
+      || scev_analyzable_p (def, region))
+    return;
+
+  def_bb = gimple_bb (stmt);
+
+  FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
+    if (def_bb != gimple_bb (use_stmt)
+	&& !is_gimple_debug (use_stmt))
       {
+	gcc_assert (gimple_code (use_stmt) != GIMPLE_PHI);
+
 	if (!zero_dim_array)
 	  {
 	    zero_dim_array = create_zero_dim_array
@@ -2360,32 +2413,6 @@ rewrite_cross_bb_scalar_deps (sese region, gimple_stmt_iterator *gsi)
 /* Rewrite out of SSA all the reduction phi nodes of SCOP.  */
 
 void
-rewrite_reductions_out_of_ssa (scop_p scop)
-{
-  basic_block bb;
-  gimple_stmt_iterator psi;
-  sese region = SCOP_REGION (scop);
-
-  FOR_EACH_BB (bb)
-    if (bb_in_sese_p (bb, region))
-      for (psi = gsi_start_phis (bb); !gsi_end_p (psi);)
-	{
-	  if (scalar_close_phi_node_p (gsi_stmt (psi)))
-	    rewrite_close_phi_out_of_ssa (&psi);
-	  else if (reduction_phi_p (region, &psi))
-	    rewrite_phi_out_of_ssa (&psi);
-	}
-
-  update_ssa (TODO_update_ssa);
-#ifdef ENABLE_CHECKING
-  verify_loop_closed_ssa (true);
-#endif
-}
-
-
-/* Rewrite out of SSA all the reduction phi nodes of SCOP.  */
-
-void
 rewrite_cross_bb_scalar_deps_out_of_ssa (scop_p scop)
 {
   basic_block bb;
@@ -2395,7 +2422,10 @@ rewrite_cross_bb_scalar_deps_out_of_ssa (scop_p scop)
   FOR_EACH_BB (bb)
     if (bb_in_sese_p (bb, region))
       for (psi = gsi_start_bb (bb); !gsi_end_p (psi); gsi_next (&psi))
-	rewrite_cross_bb_scalar_deps (region, &psi);
+	{
+	  rewrite_cross_bb_phi_deps (region, psi);
+	  rewrite_cross_bb_scalar_deps (region, &psi);
+	}
 
   update_ssa (TODO_update_ssa);
 #ifdef ENABLE_CHECKING
-- 
1.7.0.4


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