Fix PR46924: Do not detect reductions outside the current SESE region.
authorSebastian Pop <sebastian.pop@amd.com>
Thu, 16 Dec 2010 22:54:17 +0000 (22:54 +0000)
committerSebastian Pop <spop@gcc.gnu.org>
Thu, 16 Dec 2010 22:54:17 +0000 (22:54 +0000)
2010-12-16  Sebastian Pop  <sebastian.pop@amd.com>

PR tree-optimization/46924
* graphite-sese-to-poly.c (detect_commutative_reduction): Do not
detect reductions outside the current SESE region.
* sese.h (stmt_in_sese_p): New.
(defined_in_sese_p): Call stmt_in_sese_p.

* gcc.dg/graphite/pr46924.c: New.

From-SVN: r167962

gcc/ChangeLog
gcc/graphite-sese-to-poly.c
gcc/sese.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/graphite/pr46924.c [new file with mode: 0644]

index 9083edc1a07824fb399ebae3d4bc2ac574ef5831..cde0107e17c6839eef46452df1e8f584278deae3 100644 (file)
@@ -1,3 +1,11 @@
+2010-12-16  Sebastian Pop  <sebastian.pop@amd.com>
+
+       PR tree-optimization/46924
+       * graphite-sese-to-poly.c (detect_commutative_reduction): Do not
+       detect reductions outside the current SESE region.
+       * sese.h (stmt_in_sese_p): New.
+       (defined_in_sese_p): Call stmt_in_sese_p.
+
 2010-12-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/46966
index 202f02861be32e29532b3fb88d29d09e6995f0c9..49250b67382afb02d7395dbb959ab55ca38856ea 100644 (file)
@@ -2858,12 +2858,12 @@ initial_value_for_loop_phi (gimple phi)
   return NULL_TREE;
 }
 
-/* Detect commutative and associative scalar reductions starting at
-   the loop closed phi node STMT.  Return the phi node of the
-   reduction cycle, or NULL.  */
+/* Detect commutative and associative scalar reductions belonging to
+   the SCOP starting at the loop closed phi node STMT.  Return the phi
+   node of the reduction cycle, or NULL.  */
 
 static gimple
-detect_commutative_reduction (gimple stmt, VEC (gimple, heap) **in,
+detect_commutative_reduction (scop_p scop, gimple stmt, VEC (gimple, heap) **in,
                              VEC (gimple, heap) **out)
 {
   if (scalar_close_phi_node_p (stmt))
@@ -2880,7 +2880,10 @@ detect_commutative_reduction (gimple stmt, VEC (gimple, heap) **in,
       gcc_assert (gimple_phi_num_args (stmt) == 1);
 
       def = SSA_NAME_DEF_STMT (arg);
-      loop_phi = detect_commutative_reduction (def, in, out);
+      if (!stmt_in_sese_p (def, SCOP_REGION (scop)))
+       return NULL;
+
+      loop_phi = detect_commutative_reduction (scop, def, in, out);
 
       if (loop_phi)
        {
@@ -3019,7 +3022,7 @@ rewrite_commutative_reductions_out_of_ssa_close_phi (scop_p scop,
   VEC (gimple, heap) *in = VEC_alloc (gimple, heap, 10);
   VEC (gimple, heap) *out = VEC_alloc (gimple, heap, 10);
 
-  detect_commutative_reduction (close_phi, &in, &out);
+  detect_commutative_reduction (scop, close_phi, &in, &out);
   res = VEC_length (gimple, in) > 0;
   if (res)
     translate_scalar_reduction_to_array (scop, in, out);
index 10bf874a174175ec9b23399c52c7d5a23a0e754e..97807d820089ffb7bc9f2f56d4488327e8bd821a 100644 (file)
@@ -114,15 +114,22 @@ bb_in_sese_p (basic_block bb, sese region)
   return bb_in_region (bb, entry, exit);
 }
 
+/* Returns true when STMT is defined in REGION.  */
+
+static inline bool
+stmt_in_sese_p (gimple stmt, sese region)
+{
+  basic_block bb = gimple_bb (stmt);
+  return bb && bb_in_sese_p (bb, region);
+}
+
 /* Returns true when NAME is defined in REGION.  */
 
 static inline bool
 defined_in_sese_p (tree name, sese region)
 {
   gimple stmt = SSA_NAME_DEF_STMT (name);
-  basic_block bb = gimple_bb (stmt);
-
-  return bb && bb_in_sese_p (bb, region);
+  return stmt_in_sese_p (stmt, region);
 }
 
 /* Returns true when LOOP is in REGION.  */
index a90d1ee4240103880891311086f6decc98e5d077..df91d0995ad76bf1cdddfa615075b8938a5eb157 100644 (file)
@@ -1,3 +1,8 @@
+2010-12-16  Sebastian Pop  <sebastian.pop@amd.com>
+
+       PR tree-optimization/46924
+       * gcc.dg/graphite/pr46924.c: New.
+
 2010-12-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/46966
diff --git a/gcc/testsuite/gcc.dg/graphite/pr46924.c b/gcc/testsuite/gcc.dg/graphite/pr46924.c
new file mode 100644 (file)
index 0000000..5788c2c
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-options "-O -fgraphite-identity -ffast-math -fno-tree-loop-im" } */
+
+struct S
+{
+  int n;
+  float *a;
+};
+
+float foo (struct S *s)
+{
+  float f = 0, g=0;
+  int i;
+  for (i = 0; i < s->n; i++)
+    f += s->a[i];
+  for (i = 0; i < s->n; i++)
+    ;
+  return f;
+}