Patchwork [27/65] Fix 416.gamess miscompile: special case the rewrite of degenerate phi nodes.

login
register
mail settings
Submitter Sebastian Pop
Date Aug. 2, 2010, 8:20 p.m.
Message ID <1280780438-17543-28-git-send-email-sebpop@gmail.com>
Download mbox | patch
Permalink /patch/60623/
State New
Headers show

Comments

Sebastian Pop - Aug. 2, 2010, 8:20 p.m.
From: spop <spop@138bc75d-0d04-0410-961f-82ee72b054a4>

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

	* graphite-sese-to-poly.c (rewrite_degenerate_phi): New.
	(rewrite_reductions_out_of_ssa): Call it for degenerate_phi_result.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/graphite@161360 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog               |    5 +++++
 gcc/ChangeLog.graphite      |    5 +++++
 gcc/graphite-sese-to-poly.c |   40 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 49 insertions(+), 1 deletions(-)

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2013c55..397839b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@ 
 2010-08-02  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (rewrite_degenerate_phi): New.
+	(rewrite_reductions_out_of_ssa): Call it for degenerate_phi_result.
+
+2010-08-02  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite-sese-to-poly.c (rewrite_cross_bb_phi_deps): Call
 	rewrite_close_phi_out_of_ssa.
 
diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index ee63b7c..a488c39 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,5 +1,10 @@ 
 2010-06-24  Sebastian Pop  <sebastian.pop@amd.com>
 
+	* graphite-sese-to-poly.c (rewrite_degenerate_phi): New.
+	(rewrite_reductions_out_of_ssa): Call it for degenerate_phi_result.
+
+2010-06-24  Sebastian Pop  <sebastian.pop@amd.com>
+
 	* graphite-sese-to-poly.c (rewrite_cross_bb_phi_deps): Call
 	rewrite_close_phi_out_of_ssa.
 
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 8857946..62064c4 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2272,6 +2272,37 @@  rewrite_phi_out_of_ssa (gimple_stmt_iterator *psi)
   gsi_insert_seq_before (&gsi, stmts, GSI_NEW_STMT);
 }
 
+/* Rewrite the degenerate phi node at position PSI from the degenerate
+   form "x = phi (y, y, ..., y)" to "x = y".  */
+
+static void
+rewrite_degenerate_phi (gimple_stmt_iterator *psi)
+{
+  tree rhs;
+  gimple stmt;
+  gimple_stmt_iterator gsi;
+  gimple phi = gsi_stmt (*psi);
+  tree res = gimple_phi_result (phi);
+  basic_block bb;
+
+  if (!is_gimple_reg (res))
+    {
+      gsi_next (psi);
+      return;
+    }
+
+  bb = gimple_bb (phi);
+  rhs = degenerate_phi_result (phi);
+  gcc_assert (rhs);
+
+  stmt = gimple_build_assign (res, rhs);
+  remove_phi_node (psi, false);
+  SSA_NAME_DEF_STMT (res) = stmt;
+
+  gsi = gsi_after_labels (bb);
+  gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
+}
+
 /* Rewrite out of SSA all the reduction phi nodes of SCOP.  */
 
 void
@@ -2285,8 +2316,15 @@  rewrite_reductions_out_of_ssa (scop_p scop)
     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)))
+	  gimple phi = gsi_stmt (psi);
+
+	  if (gimple_phi_num_args (phi) > 1
+	      && degenerate_phi_result (phi))
+	    rewrite_degenerate_phi (&psi);
+
+	  else if (scalar_close_phi_node_p (phi))
 	    rewrite_close_phi_out_of_ssa (&psi);
+
 	  else if (reduction_phi_p (region, &psi))
 	    rewrite_phi_out_of_ssa (&psi);
 	}