diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9aa322c7695..e313596af8c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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.
+
 2010-08-02  Sebastian Pop  <sebastian.pop@amd.com>
 
 	* graphite-sese-to-poly.c (rewrite_cross_bb_phi_deps): Remove dead code.
diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite
index c2be7c736d7..ee63b7c979d 100644
--- a/gcc/ChangeLog.graphite
+++ b/gcc/ChangeLog.graphite
@@ -1,3 +1,10 @@
+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.
+
+	* gcc.dg/graphite/id-22.c: New.
+
 2010-06-24  Sebastian Pop  <sebastian.pop@amd.com>
 
 	* graphite-sese-to-poly.c (rewrite_cross_bb_phi_deps): Remove dead code.
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 318401e2d9b..8857946d1eb 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -2361,8 +2361,12 @@ rewrite_cross_bb_phi_deps (sese region, gimple_stmt_iterator gsi)
   FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
     if (gimple_code (use_stmt) == GIMPLE_PHI)
       {
-	gimple_stmt_iterator si = gsi_for_stmt (use_stmt);
-	rewrite_phi_out_of_ssa (&si);
+	gimple_stmt_iterator psi = gsi_for_stmt (use_stmt);
+
+	if (scalar_close_phi_node_p (gsi_stmt (psi)))
+	  rewrite_close_phi_out_of_ssa (&psi);
+	else
+	  rewrite_phi_out_of_ssa (&psi);
       }
 }
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 17ee09a5952..55c4314bc0b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2010-08-02  Sebastian Pop  <sebastian.pop@amd.com>
+
+	* gcc.dg/graphite/id-22.c: New.
+
 2010-08-02  Sebastian Pop  <sebastian.pop@amd.com>
 
 	* gcc.dg/graphite/run-id-2.c: Call abort.
diff --git a/gcc/testsuite/gcc.dg/graphite/id-22.c b/gcc/testsuite/gcc.dg/graphite/id-22.c
new file mode 100644
index 00000000000..d825542158b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/id-22.c
@@ -0,0 +1,15 @@
+typedef float rvec[3];
+float calc_similar_ind (int nind, rvec x[])
+{
+  int i, j, d;
+  float m, tm, xd, rd;
+  for(j=0; j<nind; j++) {
+    i = x[j][0];
+    tm += m;
+    for(d=0 ; d<3; d++) {
+      xd = x[i][d] - x[i][d];
+      rd += m * xd;
+    }
+  }
+    return rd/tm;
+}