diff mbox

[graphite] Remove limit_scops

Message ID 1441407423-23593-1-git-send-email-hiraditya@msn.com
State New
Headers show

Commit Message

Aditya K Sept. 4, 2015, 10:57 p.m. UTC
This patch removes graphite-scop-detection.c:limit_scops function and fix
related issues arising because of that. The functionality limit_scop was added
as an intermediate step to discard the loops which graphite could not
handle. Removing limit_scop required handling of different cases of loops and
surrounding code.  The scop is now larger so most test cases required 'number of
scops detected' to be fixed. By increasing the size of scop we can now optimize
loops which are 'siblings' of each other. This could enable loop fusion on a
number of loops. Since in the graphite framework we mostly want to opimize
loop-nests/adjacent-loops, we now discard scops with less than 2 loops. We
also discard scops without any data references.


Essentially:
 - Remove limite_scops.
 - Only select scops when there are at least two loops (loop nest or, side by side).
 - Discard loops without data-refs.
 - Fix test cases.


Passes bootstrap and reg-test.

gcc/ChangeLog:

2015-09-02  Aditya Kumar  <hiraditya@msn.com>
            Sebastian Pop  <s.pop@samsung.com>

        * graphite-isl-ast-to-gimple.c (gcc_expression_from_isl_ast_expr_id):
        Return the parameter if it was saved in corresponding
        parameter_rename_map of the region.
        (copy_def): Copy def from sese region to the newly created region.
        (copy_internal_parameters): Copy all the internal parameters defined
        within a region to the newly created region.
        (graphite_regenerate_ast_isl): Copy parameters to the new region before
        translating isl to gimple.
        * graphite-scop-detection.c (graphite_can_represent_loop): Bail out if
          the loop-nest does not have any data-references.
        (build_graphite_scops): Create a scop only when there is at least one
        loop inside it.
        (contains_only_close_phi_nodes): Deleted.
        (print_graphite_scop_statistics): Remove printing of scop-statistics
        before limit_scops.
        (limit_scops): Deleted.
        (build_scops): Removed call to limit_scops.
        * sese.c (new_sese): Construct.
        (free_sese): Destruct.
        (sese_add_exit_phis_edge): update_stmt after exit phi edge has been
        added.
        (set_rename): Pass sese region so that parameters inside the region can
        be added to its parameter_rename_map.        
        (rename_uses): Pass sese region.       
        (graphite_copy_stmts_from_block): Do not copy parameters that have been
        generated in the header of the scop. For each SSA_NAME in the
        parameter_rename_map rename its usage.
        (invariant_in_sese_p_rec): Return false if tree t is defined outside
        sese region.
        (scalar_evolution_in_region): If the tree t is invariant just return t.
        * sese.h: Added a parameter renamne map (parameter_rename_map_t) to
          struct sese to keep track of all the parameters which need renaming.
        * tree-data-ref.c (loop_nest_has_data_refs): Check if a loop nest has
          any data-refs.
        * tree-data-ref.h: Declaration of loop_nest_has_data_refs.


gcc/testsuite/ChangeLog:

2015-09-02  Aditya Kumar  <hiraditya@msn.com>
            Sebastian Pop  <s.pop@samsung.com>

        * gcc.dg/graphite/block-0.c: Modifed test case to match current output.
        * gcc.dg/graphite/block-1.c: Same.
        * gcc.dg/graphite/block-5.c: Same.
        * gcc.dg/graphite/block-6.c: Same.
        * gcc.dg/graphite/interchange-1.c: Same.
        * gcc.dg/graphite/interchange-10.c: Same.
        * gcc.dg/graphite/interchange-11.c: Same.
        * gcc.dg/graphite/interchange-13.c: Same.
        * gcc.dg/graphite/interchange-14.c: Same.
        * gcc.dg/graphite/interchange-3.c: Same.
        * gcc.dg/graphite/interchange-4.c: Same.
        * gcc.dg/graphite/interchange-7.c: Same.
        * gcc.dg/graphite/interchange-8.c: Same.
        * gcc.dg/graphite/interchange-9.c: Same.
        * gcc.dg/graphite/isl-codegen-loop-dumping.c: Same.
        * gcc.dg/graphite/pr35356-1.c (foo): Same.
        * gcc.dg/graphite/pr37485.c: Same.
        * gcc.dg/graphite/scop-0.c (int toto): Same.
        * gcc.dg/graphite/scop-1.c: Same.
        * gcc.dg/graphite/scop-10.c: Same.
        * gcc.dg/graphite/scop-11.c: Same.
        * gcc.dg/graphite/scop-12.c: Same.
        * gcc.dg/graphite/scop-13.c: Same.
        * gcc.dg/graphite/scop-16.c: Same.
        * gcc.dg/graphite/scop-17.c: Same.
        * gcc.dg/graphite/scop-18.c: Same.
        * gcc.dg/graphite/scop-2.c: Same.
        * gcc.dg/graphite/scop-21.c (int test): Same.
        * gcc.dg/graphite/scop-22.c (void foo): Same.
        * gcc.dg/graphite/scop-4.c: Same.
        * gcc.dg/graphite/scop-5.c: Same.
        * gcc.dg/graphite/scop-6.c: Same.
        * gcc.dg/graphite/scop-7.c: Same.
        * gcc.dg/graphite/scop-8.c: Same.
        * gcc.dg/graphite/scop-9.c: Same.
        * gcc.dg/graphite/scop-mvt.c (void mvt): Introduced dependency so that
          data-refs remain inside the inner loop.
        * gcc.dg/graphite/uns-block-1.c: Modifed test case to match o/p.
        * gcc.dg/graphite/uns-interchange-14.c: Same.
        * gcc.dg/graphite/uns-interchange-9.c: Same.


libgomp/ChangeLog:

2015-09-04  Aditya Kumar  <hiraditya@msn.com>
            Sebastian Pop  <s.pop@samsung.com>

        * testsuite/libgomp.graphite/bounds.c (int foo): Modifed test case to
          match o/p.
        * testsuite/libgomp.graphite/force-parallel-1.c (void parloop): Same.
        * testsuite/libgomp.graphite/force-parallel-4.c: Same.
        * testsuite/libgomp.graphite/force-parallel-5.c: Same.
        * testsuite/libgomp.graphite/force-parallel-7.c: Same.
        * testsuite/libgomp.graphite/force-parallel-8.c: Same.



---
 gcc/graphite-isl-ast-to-gimple.c                   |  81 ++++++++++++++-
 gcc/graphite-scop-detection.c                      | 110 +++++----------------
 gcc/sese.c                                         |  80 ++++++++++++++-
 gcc/sese.h                                         |   5 +
 gcc/testsuite/gcc.dg/graphite/block-0.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/block-1.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/block-5.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/block-6.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-1.c      |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-10.c     |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-11.c     |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-13.c     |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-14.c     |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-3.c      |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-4.c      |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-7.c      |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-8.c      |   2 +-
 gcc/testsuite/gcc.dg/graphite/interchange-9.c      |   2 +-
 .../gcc.dg/graphite/isl-codegen-loop-dumping.c     |   4 +-
 gcc/testsuite/gcc.dg/graphite/pr35356-1.c          |   4 +
 gcc/testsuite/gcc.dg/graphite/pr37485.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-0.c             |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-1.c             |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-10.c            |   4 +-
 gcc/testsuite/gcc.dg/graphite/scop-11.c            |   3 +-
 gcc/testsuite/gcc.dg/graphite/scop-12.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-13.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-16.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-17.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-18.c            |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-2.c             |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-21.c            |   3 +
 gcc/testsuite/gcc.dg/graphite/scop-22.c            |   3 +
 gcc/testsuite/gcc.dg/graphite/scop-4.c             |   2 +-
 gcc/testsuite/gcc.dg/graphite/scop-5.c             |   4 +-
 gcc/testsuite/gcc.dg/graphite/scop-6.c             |   3 +-
 gcc/testsuite/gcc.dg/graphite/scop-7.c             |   3 +-
 gcc/testsuite/gcc.dg/graphite/scop-8.c             |   5 +-
 gcc/testsuite/gcc.dg/graphite/scop-9.c             |   4 +-
 gcc/testsuite/gcc.dg/graphite/scop-mvt.c           |   6 +-
 gcc/testsuite/gcc.dg/graphite/uns-block-1.c        |   3 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c |   2 +-
 gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c  |   2 +-
 gcc/tree-data-ref.c                                |  43 ++++++++
 gcc/tree-data-ref.h                                |   1 +
 libgomp/testsuite/libgomp.graphite/bounds.c        |   2 +
 .../testsuite/libgomp.graphite/force-parallel-1.c  |   7 +-
 .../testsuite/libgomp.graphite/force-parallel-4.c  |   1 -
 .../testsuite/libgomp.graphite/force-parallel-5.c  |   2 +-
 .../testsuite/libgomp.graphite/force-parallel-7.c  |   2 +-
 .../testsuite/libgomp.graphite/force-parallel-8.c  |   2 -
 51 files changed, 286 insertions(+), 151 deletions(-)

Comments

Tobias Grosser Sept. 7, 2015, 2:07 p.m. UTC | #1
On 09/05/2015 12:57 AM, Aditya Kumar wrote:
> This patch removes graphite-scop-detection.c:limit_scops function and fix
> related issues arising because of that. The functionality limit_scop was added
> as an intermediate step to discard the loops which graphite could not
> handle. Removing limit_scop required handling of different cases of loops and
> surrounding code.  The scop is now larger so most test cases required 'number of
> scops detected' to be fixed. By increasing the size of scop we can now optimize
> loops which are 'siblings' of each other. This could enable loop fusion on a
> number of loops. Since in the graphite framework we mostly want to opimize
> loop-nests/adjacent-loops, we now discard scops with less than 2 loops. We
> also discard scops without any data references.
>
>
> Essentially:
>   - Remove limite_scops.
>   - Only select scops when there are at least two loops (loop nest or, side by side).
>   - Discard loops without data-refs.
>   - Fix test cases.
>
>
> Passes bootstrap and reg-test.

I did not check every detail, but conceptually this is looks good to me.

Tobias
diff mbox

Patch

diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c
index 5434bfd..a8c99c3 100644
--- a/gcc/graphite-isl-ast-to-gimple.c
+++ b/gcc/graphite-isl-ast-to-gimple.c
@@ -57,7 +57,9 @@  extern "C" {
 #include "tree-ssa-loop-manip.h"
 #include "tree-scalar-evolution.h"
 #include "gimple-ssa.h"
+#include "tree-phinodes.h"
 #include "tree-into-ssa.h"
+#include "ssa-iterators.h"
 #include <map>
 #include "graphite-isl-ast-to-gimple.h"
 
@@ -286,7 +288,12 @@  gcc_expression_from_isl_ast_expr_id (tree type,
   gcc_assert (res != ip.end () &&
 	      "Could not map isl_id to tree expression");
   isl_ast_expr_free (expr_id);
-  return fold_convert (type, res->second);
+  tree t = res->second;
+  tree *val = region->parameter_rename_map->get(t);
+
+  if (!val)
+   val = &t;
+  return fold_convert (type, *val);
 }
 
 /* Converts an isl_ast_expr_int expression E to a GCC expression tree of
@@ -1063,6 +1070,69 @@  scop_to_isl_ast (scop_p scop, ivs_params &ip)
   return ast_isl;
 }
 
+/* Copy def from sese REGION to the newly created TO_REGION. TR is defined by
+   DEF_STMT. GSI points to entry basic block of the TO_REGION.  */
+
+static void
+copy_def(tree tr, gimple def_stmt, sese region, sese to_region, gimple_stmt_iterator *gsi)
+{
+  if (!defined_in_sese_p (tr, region))
+    return;
+  ssa_op_iter iter;
+  use_operand_p use_p;
+
+  FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_USE)
+    {
+      tree use_tr = USE_FROM_PTR (use_p);
+
+      /* Do not copy parameters that have been generated in the header of the
+	 scop.  */
+      if (region->parameter_rename_map->get(use_tr))
+	continue;
+
+      gimple def_of_use = SSA_NAME_DEF_STMT (use_tr);
+      if (!def_of_use)
+	continue;
+
+      copy_def (use_tr, def_of_use, region, to_region, gsi);
+    }
+
+  gimple copy = gimple_copy (def_stmt);
+  gsi_insert_after (gsi, copy, GSI_NEW_STMT);
+
+  /* Create new names for all the definitions created by COPY and
+     add replacement mappings for each new name.  */
+  def_operand_p def_p;
+  ssa_op_iter op_iter;
+  FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS)
+    {
+      tree old_name = DEF_FROM_PTR (def_p);
+      tree new_name = create_new_def_for (old_name, copy, def_p);
+      region->parameter_rename_map->put(old_name, new_name);
+    }
+
+  update_stmt (copy);
+}
+
+static void
+copy_internal_parameters(sese region, sese to_region)
+{
+  /* For all the parameters which definitino is in the if_region->false_region,
+     insert code on true_region (if_region->true_region->entry). */
+
+  int i;
+  tree tr;
+  gimple_stmt_iterator gsi = gsi_start_bb(to_region->entry->dest);
+
+  FOR_EACH_VEC_ELT (region->params, i, tr)
+    {
+      // If def is not in region.
+      gimple def_stmt = SSA_NAME_DEF_STMT (tr);
+      if (def_stmt)
+	copy_def (tr, def_stmt, region, to_region, &gsi);
+    }
+}
+
 /* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
    the given SCOP.  Return true if code generation succeeded.
 
@@ -1102,10 +1172,13 @@  graphite_regenerate_ast_isl (scop_p scop)
 
   context_loop = SESE_ENTRY (region)->src->loop_father;
 
-  translate_isl_ast_to_gimple t (region);
+  /* Copy all the parameters which are defined in the region.  */
+  copy_internal_parameters(if_region->false_region, if_region->true_region);
 
-  t.translate_isl_ast (context_loop, root_node, if_region->true_region->entry,
-		     ip);
+  translate_isl_ast_to_gimple t(region);
+  edge e = single_succ_edge (if_region->true_region->entry->dest);
+  split_edge (e);
+  t.translate_isl_ast (context_loop, root_node, e, ip);
 
   mark_virtual_operands_for_renaming (cfun);
   update_ssa (TODO_update_ssa);
diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index dbd9842..638b494 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -472,6 +472,17 @@  graphite_can_represent_loop (basic_block scop_entry, loop_p loop)
   tree niter;
   struct tree_niter_desc niter_desc;
 
+  if (!loop_nest_has_data_refs (loop))
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	{
+	  fprintf (dump_file, "[scop-detection-fail] ");
+	  fprintf (dump_file, "Loop %d does not have any data reference.\n",
+		   loop->num);
+	}
+      return false;
+    }
+
   /* FIXME: For the moment, graphite cannot be used on loops that
      iterate using induction variables that wrap.  */
 
@@ -1155,8 +1166,17 @@  build_graphite_scops (vec<sd_region> regions,
       if (!exit)
 	continue;
 
-      scop = new_scop (new_sese (entry, exit));
-      scops->safe_push (scop);
+      sese sese_reg = new_sese (entry, exit);
+      scop = new_scop (sese_reg);
+
+      build_sese_loop_nests (sese_reg);
+
+      /* Scops with one or no loops are not interesting.  */
+      if (SESE_LOOP_NEST (sese_reg).length () > 1)
+	scops->safe_push (scop);
+      else if (dump_file && dump_flags)
+	fprintf (dump_file, "Discarded scop: %d loops\n",
+		 SESE_LOOP_NEST (sese_reg).length ());
 
       /* Are there overlapping SCoPs?  */
 #ifdef ENABLE_CHECKING
@@ -1172,20 +1192,6 @@  build_graphite_scops (vec<sd_region> regions,
     }
 }
 
-/* Returns true when BB contains only close phi nodes.  */
-
-static bool
-contains_only_close_phi_nodes (basic_block bb)
-{
-  gimple_stmt_iterator gsi;
-
-  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
-    if (gimple_code (gsi_stmt (gsi)) != GIMPLE_LABEL)
-      return false;
-
-  return true;
-}
-
 /* Print statistics for SCOP to FILE.  */
 
 static void
@@ -1232,17 +1238,6 @@  print_graphite_scop_statistics (FILE* file, scop_p scop)
 	}
 
     }
-
-  fprintf (file, "\nBefore limit_scops SCoP statistics (");
-  fprintf (file, "BBS:%ld, ", n_bbs);
-  fprintf (file, "LOOPS:%ld, ", n_loops);
-  fprintf (file, "CONDITIONS:%ld, ", n_conditions);
-  fprintf (file, "STMTS:%ld)\n", n_stmts);
-  fprintf (file, "\nBefore limit_scops SCoP profiling statistics (");
-  fprintf (file, "BBS:%ld, ", n_p_bbs);
-  fprintf (file, "LOOPS:%ld, ", n_p_loops);
-  fprintf (file, "CONDITIONS:%ld, ", n_p_conditions);
-  fprintf (file, "STMTS:%ld)\n", n_p_stmts);
 }
 
 /* Print statistics for SCOPS to FILE.  */
@@ -1257,66 +1252,6 @@  print_graphite_statistics (FILE* file, vec<scop_p> scops)
     print_graphite_scop_statistics (file, scop);
 }
 
-/* We limit all SCoPs to SCoPs, that are completely surrounded by a loop.
-
-   Example:
-
-   for (i      |
-     {         |
-       for (j  |  SCoP 1
-       for (k  |
-     }         |
-
-   * SCoP frontier, as this line is not surrounded by any loop. *
-
-   for (l      |  SCoP 2
-
-   This is necessary as scalar evolution and parameter detection need a
-   outermost loop to initialize parameters correctly.
-
-   TODO: FIX scalar evolution and parameter detection to allow more flexible
-         SCoP frontiers.  */
-
-static void
-limit_scops (vec<scop_p> *scops)
-{
-  auto_vec<sd_region, 3> regions;
-
-  int i;
-  scop_p scop;
-
-  FOR_EACH_VEC_ELT (*scops, i, scop)
-    {
-      int j;
-      loop_p loop;
-      sese region = SCOP_REGION (scop);
-      build_sese_loop_nests (region);
-
-      FOR_EACH_VEC_ELT (SESE_LOOP_NEST (region), j, loop)
-        if (!loop_in_sese_p (loop_outer (loop), region)
-	    && single_exit (loop))
-          {
-	    sd_region open_scop;
-	    open_scop.entry = loop->header;
-	    open_scop.exit = single_exit (loop)->dest;
-
-	    /* This is a hack on top of the limit_scops hack.  The
-	       limit_scops hack should disappear all together.  */
-	    if (single_succ_p (open_scop.exit)
-		&& contains_only_close_phi_nodes (open_scop.exit))
-	      open_scop.exit = single_succ_edge (open_scop.exit)->dest;
-
-	    regions.safe_push (open_scop);
-	  }
-    }
-
-  free_scops (*scops);
-  scops->create (3);
-
-  create_sese_edges (regions);
-  build_graphite_scops (regions, scops);
-}
-
 /* Returns true when P1 and P2 are close phis with the same
    argument.  */
 
@@ -1504,7 +1439,6 @@  build_scops (vec<scop_p> *scops)
   if (dump_file && (dump_flags & TDF_DETAILS))
     print_graphite_statistics (dump_file, *scops);
 
-  limit_scops (scops);
   regions.release ();
 
   if (dump_file && (dump_flags & TDF_DETAILS))
diff --git a/gcc/sese.c b/gcc/sese.c
index 2dedd95..3b716f5 100644
--- a/gcc/sese.c
+++ b/gcc/sese.c
@@ -267,6 +267,7 @@  new_sese (edge entry, edge exit)
   SESE_LOOP_NEST (region).create (3);
   SESE_ADD_PARAMS (region) = true;
   SESE_PARAMS (region).create (3);
+  region->parameter_rename_map = new parameter_rename_map_t;
 
   return region;
 }
@@ -281,6 +282,8 @@  free_sese (sese region)
 
   SESE_PARAMS (region).release ();
   SESE_LOOP_NEST (region).release ();
+  delete region->parameter_rename_map;
+  region->parameter_rename_map = NULL;
 
   XDELETE (region);
 }
@@ -294,6 +297,7 @@  sese_add_exit_phis_edge (basic_block exit, tree use, edge false_e, edge true_e)
   create_new_def_for (use, phi, gimple_phi_result_ptr (phi));
   add_phi_arg (phi, use, false_e, UNKNOWN_LOCATION);
   add_phi_arg (phi, use, true_e, UNKNOWN_LOCATION);
+  update_stmt (phi);
 }
 
 /* Insert in the block BB phi nodes for variables defined in REGION
@@ -373,12 +377,19 @@  get_rename (rename_map_type *rename_map, tree old_name)
 /* Register in RENAME_MAP the rename tuple (OLD_NAME, EXPR).  */
 
 static void
-set_rename (rename_map_type *rename_map, tree old_name, tree expr)
+set_rename (rename_map_type *rename_map, tree old_name, tree expr, sese region)
 {
   if (old_name == expr)
     return;
 
   rename_map->put (old_name, expr);
+
+  tree t;
+  int i;
+  /* For a parameter of a scop we dont want to rename it.  */
+  FOR_EACH_VEC_ELT (SESE_PARAMS (region), i, t)
+    if (old_name == t)
+      region->parameter_rename_map->put(old_name, expr);
 }
 
 /* Renames the scalar uses of the statement COPY, using the
@@ -484,7 +495,7 @@  rename_uses (gimple copy, rename_map_type *rename_map,
 	    recompute_tree_invariant_for_addr_expr (rhs);
 	}
 
-      set_rename (rename_map, old_name, new_expr);
+      set_rename (rename_map, old_name, new_expr, region);
     }
 
   return changed;
@@ -525,6 +536,14 @@  graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
 	  && scev_analyzable_p (lhs, region))
 	continue;
 
+      /* Do not copy parameters that have been generated in the header of the
+	 scop.  */
+      if (is_gimple_assign (stmt)
+	  && (lhs = gimple_assign_lhs (stmt))
+	  && TREE_CODE (lhs) == SSA_NAME
+	  && region->parameter_rename_map->get(lhs))
+	continue;
+
       /* Create a new copy of STMT and duplicate STMT's virtual
 	 operands.  */
       copy = gimple_copy (stmt);
@@ -539,7 +558,7 @@  graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
  	{
  	  tree old_name = DEF_FROM_PTR (def_p);
  	  tree new_name = create_new_def_for (old_name, copy, def_p);
-	  set_rename (rename_map, old_name, new_name);
+	  set_rename (rename_map, old_name, new_name, region);
  	}
 
       if (rename_uses (copy, rename_map, &gsi_tgt, region, loop, iv_map,
@@ -549,6 +568,25 @@  graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
 	  fold_stmt_inplace (&gsi_tgt);
 	}
 
+      /* For each SSA_NAME in the parameter_rename_map rename their usage.  */
+      ssa_op_iter iter;
+      use_operand_p use_p;
+      if (!is_gimple_debug (copy))
+	FOR_EACH_SSA_USE_OPERAND (use_p, copy, iter, SSA_OP_USE)
+	  {
+	    tree old_name = USE_FROM_PTR (use_p);
+
+	    if (TREE_CODE (old_name) != SSA_NAME
+		|| SSA_NAME_IS_DEFAULT_DEF (old_name))
+	      continue;
+
+	    tree *new_expr = region->parameter_rename_map->get (old_name);
+	    if (!new_expr)
+	      continue;
+
+	    replace_exp (use_p, *new_expr);
+	  }
+
       update_stmt (copy);
     }
 }
@@ -722,6 +760,35 @@  set_ifsese_condition (ifsese if_region, tree condition)
   gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT);
 }
 
+/* Return false if T is completely defined outside REGION.  */
+
+static bool
+invariant_in_sese_p_rec (tree t, sese region)
+{
+  ssa_op_iter iter;
+  use_operand_p use_p;
+  if (!defined_in_sese_p (t, region))
+    return true;
+
+  gimple stmt = SSA_NAME_DEF_STMT (t);
+
+  if (gimple_code (stmt) == GIMPLE_PHI
+      || gimple_code (stmt) == GIMPLE_CALL)
+    return false;
+
+  FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
+    {
+      tree use = USE_FROM_PTR (use_p);
+      if (!defined_in_sese_p (use, region))
+	continue;
+
+      if (!invariant_in_sese_p_rec (use, region))
+	return false;
+    }
+
+  return true;
+}
+
 /* Returns the scalar evolution of T in REGION.  Every variable that
    is not defined in the REGION is considered a parameter.  */
 
@@ -752,6 +819,9 @@  scalar_evolution_in_region (sese region, loop_p loop, tree t)
       t = compute_overall_effect_of_inner_loop (def_loop, t);
       return t;
     }
-  else
-    return instantiate_scev (before, loop, t);
+
+  if (invariant_in_sese_p_rec (t, region))
+    return t;
+
+  return instantiate_scev (before, loop, t);
 }
diff --git a/gcc/sese.h b/gcc/sese.h
index 52aa868..b025a4d 100644
--- a/gcc/sese.h
+++ b/gcc/sese.h
@@ -22,6 +22,8 @@  along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_SESE_H
 #define GCC_SESE_H
 
+typedef hash_map<tree, tree> parameter_rename_map_t;
+
 /* A Single Entry, Single Exit region is a part of the CFG delimited
    by two edges.  */
 typedef struct sese_s
@@ -32,6 +34,9 @@  typedef struct sese_s
   /* Parameters used within the SCOP.  */
   vec<tree> params;
 
+  /* Parameters to be renamed.  */
+  parameter_rename_map_t *parameter_rename_map;
+
   /* Loops completely contained in the SCOP.  */
   bitmap loops;
   vec<loop_p> loop_nest;
diff --git a/gcc/testsuite/gcc.dg/graphite/block-0.c b/gcc/testsuite/gcc.dg/graphite/block-0.c
index cb08a5f..24b3bd0 100644
--- a/gcc/testsuite/gcc.dg/graphite/block-0.c
+++ b/gcc/testsuite/gcc.dg/graphite/block-0.c
@@ -42,4 +42,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "not tiled" 3 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "not tiled" 2 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/block-1.c b/gcc/testsuite/gcc.dg/graphite/block-1.c
index 19f9f20..bb81a95 100644
--- a/gcc/testsuite/gcc.dg/graphite/block-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/block-1.c
@@ -45,4 +45,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 5 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 6 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/block-5.c b/gcc/testsuite/gcc.dg/graphite/block-5.c
index d30abf80..2f4b2f5 100644
--- a/gcc/testsuite/gcc.dg/graphite/block-5.c
+++ b/gcc/testsuite/gcc.dg/graphite/block-5.c
@@ -53,4 +53,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 4 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/block-6.c b/gcc/testsuite/gcc.dg/graphite/block-6.c
index 9f03448..36e9783 100644
--- a/gcc/testsuite/gcc.dg/graphite/block-6.c
+++ b/gcc/testsuite/gcc.dg/graphite/block-6.c
@@ -48,4 +48,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 4 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-1.c b/gcc/testsuite/gcc.dg/graphite/interchange-1.c
index b9f12c7..2c58ac2 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-1.c
@@ -49,4 +49,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-10.c b/gcc/testsuite/gcc.dg/graphite/interchange-10.c
index 29e11c7..9d48644 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-10.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-10.c
@@ -46,4 +46,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 4 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 6 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-11.c b/gcc/testsuite/gcc.dg/graphite/interchange-11.c
index afd7123..4f6918d 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-11.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-11.c
@@ -46,4 +46,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-13.c b/gcc/testsuite/gcc.dg/graphite/interchange-13.c
index 0e722e2..c9ea048 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-13.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-13.c
@@ -50,4 +50,4 @@  main (void)
 }
 
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-14.c b/gcc/testsuite/gcc.dg/graphite/interchange-14.c
index 55c6002..151bfe7 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-14.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-14.c
@@ -54,4 +54,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 7 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 6 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-3.c b/gcc/testsuite/gcc.dg/graphite/interchange-3.c
index cdc0202..ebdeef7 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-3.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-3.c
@@ -47,4 +47,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-4.c b/gcc/testsuite/gcc.dg/graphite/interchange-4.c
index 6712565..9a50e7a 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-4.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-4.c
@@ -46,4 +46,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-7.c b/gcc/testsuite/gcc.dg/graphite/interchange-7.c
index d99a16a..e53d30e 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-7.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-7.c
@@ -46,4 +46,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-8.c b/gcc/testsuite/gcc.dg/graphite/interchange-8.c
index 123106b..c5e7141 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-8.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-8.c
@@ -82,4 +82,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 5 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 6 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/interchange-9.c b/gcc/testsuite/gcc.dg/graphite/interchange-9.c
index e4c54ae..44a5452 100644
--- a/gcc/testsuite/gcc.dg/graphite/interchange-9.c
+++ b/gcc/testsuite/gcc.dg/graphite/interchange-9.c
@@ -44,4 +44,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 4 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/isl-codegen-loop-dumping.c b/gcc/testsuite/gcc.dg/graphite/isl-codegen-loop-dumping.c
index cb5d802..70ac24c 100644
--- a/gcc/testsuite/gcc.dg/graphite/isl-codegen-loop-dumping.c
+++ b/gcc/testsuite/gcc.dg/graphite/isl-codegen-loop-dumping.c
@@ -12,4 +12,6 @@  main (int n, int *a)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "ISL AST generated by ISL: \nfor \\(int c1 = 0; c1 < n - 1; c1 \\+= 1\\)\n  for \\(int c3 = 0; c3 < n; c3 \\+= 1\\)\n    S_4\\(c1, c3\\);" 1 "graphite"} } */
+/* { dg-final { scan-tree-dump-times "ISL AST generated by ISL: \n\\{\n  S_2\\();\n  if \\(P_19 >= 1\\)\n
+    for \\(int c1 = 0; c1 < n - 1; c1 \\+= 1\\) \\{ \n      for \\(int c3 = 0; c3 < n; c3 \\+= 1\\)\n
+        S_4\\(c1, c3\\); \n      S_6\\(c1\\);\n    \\}    \n\\}" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/pr35356-1.c b/gcc/testsuite/gcc.dg/graphite/pr35356-1.c
index 10aa493..7f0e824 100644
--- a/gcc/testsuite/gcc.dg/graphite/pr35356-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/pr35356-1.c
@@ -11,6 +11,10 @@  foo (int bar, int n, int k)
     if (i == k)
       a[i] = bar;
 
+  for (i = 0; i < n; i++)
+    if (i == k)
+      a[i] = bar;
+
   return a[bar];
 }
 
diff --git a/gcc/testsuite/gcc.dg/graphite/pr37485.c b/gcc/testsuite/gcc.dg/graphite/pr37485.c
index 0a6dfbc..47138d3 100644
--- a/gcc/testsuite/gcc.dg/graphite/pr37485.c
+++ b/gcc/testsuite/gcc.dg/graphite/pr37485.c
@@ -31,4 +31,4 @@  void fallbackSort ( UInt32* fmap,
    AssertH ( j < 256, 1005 );
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 1 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 4 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-0.c b/gcc/testsuite/gcc.dg/graphite/scop-0.c
index 9cfd5dd..abeabce 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-0.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-0.c
@@ -9,7 +9,7 @@  int toto()
   int b[100];
   int N = foo ();
 
-  for (i = 0; i < 2*N+ 100; i++)
+  for (i = 0; i < N+ 100; i++)
     for (j = 0; j < 200; j++)
       a[j][i] = a[j+1][10] + 2;
 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-1.c b/gcc/testsuite/gcc.dg/graphite/scop-1.c
index 16070d4..a569065 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-1.c
@@ -27,4 +27,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-10.c b/gcc/testsuite/gcc.dg/graphite/scop-10.c
index f14aabc..b937440 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-10.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-10.c
@@ -12,8 +12,6 @@  int toto()
         b[i+j] = b[i+j-1] + 2;
 
       if (i * 2 == i + 8)
-        bar ();
-      else 
         {
 	  for (j = 1; j < 100; j++)
 	    b[i+j] = b[i+j-1] + 2;
@@ -27,4 +25,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */ 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-11.c b/gcc/testsuite/gcc.dg/graphite/scop-11.c
index 4a72869..930571e 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-11.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-11.c
@@ -10,7 +10,6 @@  int toto()
       for (j = 0; j <= 20; j++)
         a[j] = b + i;
       b = 3;
-      bar();
     }
   else 
     {
@@ -28,4 +27,4 @@  int toto()
   return a[b];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */ 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-12.c b/gcc/testsuite/gcc.dg/graphite/scop-12.c
index 221d987..1771250 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-12.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-12.c
@@ -32,4 +32,4 @@  int toto()
   return a[b];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 5" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 0" 1 "graphite"} } */ 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-13.c b/gcc/testsuite/gcc.dg/graphite/scop-13.c
index 195b756..05bfa4c 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-13.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-13.c
@@ -37,4 +37,4 @@  int toto()
   return a[b];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 0" 1 "graphite"} } */ 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-16.c b/gcc/testsuite/gcc.dg/graphite/scop-16.c
index cacd564..6768170 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-16.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-16.c
@@ -21,4 +21,4 @@  int test ()
       foo (a[i][j]); 
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-17.c b/gcc/testsuite/gcc.dg/graphite/scop-17.c
index 2252766..3c0d880 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-17.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-17.c
@@ -20,4 +20,4 @@  int test ()
       foo (a[i][j]); 
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-18.c b/gcc/testsuite/gcc.dg/graphite/scop-18.c
index 6e1080b..3416304 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-18.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-18.c
@@ -22,4 +22,4 @@  void test (void)
         A[i][j] = B[i][k] * C[k][j];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-2.c b/gcc/testsuite/gcc.dg/graphite/scop-2.c
index a16717c..fb1a4e7 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-2.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-2.c
@@ -35,4 +35,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 4" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-21.c b/gcc/testsuite/gcc.dg/graphite/scop-21.c
index 48a6d2f..bd3f811 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-21.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-21.c
@@ -6,6 +6,9 @@  int test ()
   int i;
 
   for (i = 0; i < N; i++)
+    a[i] += 32;
+
+  for (i = 0; i < N; i++)
     {
       a[i] = i + 12;
 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-22.c b/gcc/testsuite/gcc.dg/graphite/scop-22.c
index c936428..6ff5ccd 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-22.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-22.c
@@ -7,6 +7,9 @@  void foo(int N, int *res)
   double sum = 0.0;
 
   for (i = 0; i < N; i++)
+    sum += u[i];
+
+  for (i = 0; i < N; i++)
     {
       a = u[i];
       u[i] = i * i;
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-4.c b/gcc/testsuite/gcc.dg/graphite/scop-4.c
index c6d719e..4fb0e5e 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-4.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-4.c
@@ -25,4 +25,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-5.c b/gcc/testsuite/gcc.dg/graphite/scop-5.c
index fa1c64a..8309257 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-5.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-5.c
@@ -9,6 +9,8 @@  int toto()
     {
       for (j = 0; j <= 20; j++)
         a[j] = b + i;
+      for (j = 2; j <= 23; j++)
+        a[j] = b + i;
       b = 3;
       bar();
     }
@@ -31,4 +33,4 @@  int toto()
   return a[b];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-6.c b/gcc/testsuite/gcc.dg/graphite/scop-6.c
index 2a45d6e..5ac2c1b 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-6.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-6.c
@@ -17,7 +17,6 @@  int toto()
         {
         for (k = 1; k < 100; k++)
           b[i+k] = b[i+k-1] + 2;
-        bar ();
         }
       
       for (k = 1; k < 100; k++)
@@ -27,4 +26,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */ 
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */ 
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-7.c b/gcc/testsuite/gcc.dg/graphite/scop-7.c
index 5866ca7..3e337d0 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-7.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-7.c
@@ -13,7 +13,6 @@  int toto()
 
       if (i * 2 == i + 8)
 	{
-	  bar ();
 	  for (j = 1; j < 100; j++)
 	    b[i+j] = b[i+j-1] + 2;
 	}
@@ -27,4 +26,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-8.c b/gcc/testsuite/gcc.dg/graphite/scop-8.c
index 9cdc69f..71d5c53 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-8.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-8.c
@@ -14,8 +14,7 @@  int toto()
       if (i * 2 == i + 8)
 	{
 	  for (j = 1; j < 100; j++)
-	    if (bar ())
-	      b[i+j] = b[i+j-1] + 2;
+	    b[i+j] = b[i+j-1] + 2;
 	}
       else 
 	a[i][i] = 2;
@@ -27,4 +26,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-9.c b/gcc/testsuite/gcc.dg/graphite/scop-9.c
index d879d9a..9388872 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-9.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-9.c
@@ -12,8 +12,6 @@  int toto()
         b[i+j] = b[i+j-1] + 2;
 
       if (i * 2 == i + 8)
-        bar ();
-      else 
 	a[i][i] = 2;
 
       for (k = 1; k < 100; k++)
@@ -23,4 +21,4 @@  int toto()
   return a[3][5] + b[1];
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite"} } */
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/graphite/scop-mvt.c b/gcc/testsuite/gcc.dg/graphite/scop-mvt.c
index 5d3d19f..442a3a0 100644
--- a/gcc/testsuite/gcc.dg/graphite/scop-mvt.c
+++ b/gcc/testsuite/gcc.dg/graphite/scop-mvt.c
@@ -8,16 +8,16 @@  void mvt(long N) {
 
     for (i=0; i<N; i++) {
         for (j=0; j<N; j++) {
-            x1[i] = x1[i] + a[i][j] * y_1[j];
+            x1[j] = x1[j] + a[i][j] * y_1[j];
         }
     }
     
     for (i=0; i<N; i++) {
         for (j=0; j<N; j++) {
-            x2[i] = x2[i] + a[j][i] * y_2[j];
+            x2[j] = x2[j] + a[j][i] * y_2[j];
         }
     }
 }
 
-/* { dg-final { scan-tree-dump-times "number of SCoPs: 2" 1 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite" } } */
 
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-block-1.c b/gcc/testsuite/gcc.dg/graphite/uns-block-1.c
index 12a6291..0a0ece7 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-block-1.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-block-1.c
@@ -45,4 +45,5 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 4 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 5 "graphite" } } */
+
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c b/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c
index 7ef575b..1679cc3 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-interchange-14.c
@@ -55,4 +55,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 6 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 5 "graphite" } } */
diff --git a/gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c b/gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c
index 31b1322..601169e 100644
--- a/gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c
+++ b/gcc/testsuite/gcc.dg/graphite/uns-interchange-9.c
@@ -45,4 +45,4 @@  main (void)
   return 0;
 }
 
-/* { dg-final { scan-tree-dump-times "tiled by" 2 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "tiled by" 3 "graphite" } } */
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index ebf9dd2..c0eab40 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -3927,6 +3927,49 @@  get_references_in_stmt (gimple stmt, vec<data_ref_loc, va_heap> *references)
   return clobbers_memory;
 }
 
+
+/* Returns true if the loop-nest has any data reference.  */
+
+bool
+loop_nest_has_data_refs (loop_p loop)
+{
+  basic_block *bbs = get_loop_body (loop);
+  vec<data_ref_loc> references;
+  references.create (3);
+
+  for (unsigned i = 0; i < loop->num_nodes; i++)
+    {
+      basic_block bb = bbs[i];
+      gimple_stmt_iterator bsi;
+
+      for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
+	{
+	  gimple stmt = gsi_stmt (bsi);
+	  get_references_in_stmt (stmt, &references);
+	  if (references.length ())
+	    {
+	      free (bbs);
+	      references.release ();
+	      return true;
+	    }
+	}
+    }
+  free (bbs);
+  references.release ();
+
+  if (loop->inner)
+    {
+      loop = loop->inner;
+      while (loop)
+	{
+	  if (loop_nest_has_data_refs (loop))
+	    return true;
+	  loop = loop->next;
+	}
+    }
+  return false;
+}
+
 /* Stores the data references in STMT to DATAREFS.  If there is an unanalyzable
    reference, returns false, otherwise returns true.  NEST is the outermost
    loop of the loop nest in which the references should be analyzed.  */
diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h
index 18bcc5c..0648439 100644
--- a/gcc/tree-data-ref.h
+++ b/gcc/tree-data-ref.h
@@ -322,6 +322,7 @@  extern bool find_data_references_in_stmt (struct loop *, gimple,
 extern bool graphite_find_data_references_in_stmt (loop_p, loop_p, gimple,
 						   vec<data_reference_p> *);
 tree find_data_references_in_loop (struct loop *, vec<data_reference_p> *);
+bool loop_nest_has_data_refs (loop_p loop);
 struct data_reference *create_data_ref (loop_p, loop_p, tree, gimple, bool);
 extern bool find_loop_nest (struct loop *, vec<loop_p> *);
 extern struct data_dependence_relation *initialize_data_dependence_relation
diff --git a/libgomp/testsuite/libgomp.graphite/bounds.c b/libgomp/testsuite/libgomp.graphite/bounds.c
index 822eb6a..3d2fd7a 100644
--- a/libgomp/testsuite/libgomp.graphite/bounds.c
+++ b/libgomp/testsuite/libgomp.graphite/bounds.c
@@ -3,6 +3,8 @@  int foo(int *a, int n)
   int i;
   for (i = 2; i < n; i++)
     a[i] += a[i+1];
+  for (i = 2; i < n; i++)
+    a[i] += a[i+1];
 }
 
 /* Check that Graphite dependency checking notes the dependency.  */
diff --git a/libgomp/testsuite/libgomp.graphite/force-parallel-1.c b/libgomp/testsuite/libgomp.graphite/force-parallel-1.c
index 245e64c..0393356 100644
--- a/libgomp/testsuite/libgomp.graphite/force-parallel-1.c
+++ b/libgomp/testsuite/libgomp.graphite/force-parallel-1.c
@@ -7,6 +7,9 @@  void parloop (int N)
   int i;
 
   for (i = 0; i < N; i++)
+    x[i] = i + 1;
+
+  for (i = 0; i < N; i++)
     x[i] = i + 3;
 
   for (i = 0; i < N; i++)
@@ -24,5 +27,5 @@  int main(void)
 }
 
 /* Check that parallel code generation part make the right answer.  */
-/* { dg-final { scan-tree-dump-times "1 loops carried no dependency" 1 "graphite" } } */
-/* { dg-final { scan-tree-dump-times "loopfn" 4 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "2 loops carried no dependency" 1 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "loopfn" 8 "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.graphite/force-parallel-4.c b/libgomp/testsuite/libgomp.graphite/force-parallel-4.c
index 513d58d..b58883c 100644
--- a/libgomp/testsuite/libgomp.graphite/force-parallel-4.c
+++ b/libgomp/testsuite/libgomp.graphite/force-parallel-4.c
@@ -47,7 +47,6 @@  int main(void)
 }
 
 /* Check that parallel code generation part make the right answer.  */
-/* { dg-final { scan-tree-dump-times "1 loops carried no dependency" 1 "graphite" } } */
 /* { dg-final { scan-tree-dump-times "2 loops carried no dependency" 1 "graphite" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.0" 4 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.1" 4 "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.graphite/force-parallel-5.c b/libgomp/testsuite/libgomp.graphite/force-parallel-5.c
index d599467..de31d64 100644
--- a/libgomp/testsuite/libgomp.graphite/force-parallel-5.c
+++ b/libgomp/testsuite/libgomp.graphite/force-parallel-5.c
@@ -31,6 +31,6 @@  int main(void)
 }
 
 /* Check that parallel code generation part make the right answer.  */
-/* { dg-final { scan-tree-dump-times "1 loops carried no dependency" 1 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "2 loops carried no dependency" 1 "graphite" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.0" 4 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.1" 4 "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.graphite/force-parallel-7.c b/libgomp/testsuite/libgomp.graphite/force-parallel-7.c
index 5a54d47..9d2b37c 100644
--- a/libgomp/testsuite/libgomp.graphite/force-parallel-7.c
+++ b/libgomp/testsuite/libgomp.graphite/force-parallel-7.c
@@ -31,5 +31,5 @@  int main (void)
 }
 
 /* Check that parallel code generation part make the right answer.  */
-/* { dg-final { scan-tree-dump-times "3 loops carried no dependency" 1 "graphite" } } */
+/* { dg-final { scan-tree-dump-times "5 loops carried no dependency" 1 "graphite" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.0" 4 "optimized" } } */
diff --git a/libgomp/testsuite/libgomp.graphite/force-parallel-8.c b/libgomp/testsuite/libgomp.graphite/force-parallel-8.c
index dc60f2f..32ba5ab 100644
--- a/libgomp/testsuite/libgomp.graphite/force-parallel-8.c
+++ b/libgomp/testsuite/libgomp.graphite/force-parallel-8.c
@@ -43,8 +43,6 @@  int main(void)
 }
 
 /* Check that parallel code generation part make the right answer.  */
-/* { dg-final { scan-tree-dump-times "1 loops carried no dependency" 1 "graphite" } } */
-/* { dg-final { scan-tree-dump-times "3 loops carried no dependency" 1 "graphite" } } */
 /* { dg-final { scan-tree-dump-times "5 loops carried no dependency" 1 "graphite" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.0" 4 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "loopfn.1" 4 "optimized" } } */