From 89237d1c3d44ca5f2326d2961b4f79d66c800454 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Tue, 10 Jun 2008 15:25:11 +0000 Subject: 2008-06-10 Tobias Grosser * graphite.c (is_bb_addable): Fix memory leak, handling of loops with multiple exits and conditional handling in edge cases. (is_loop_exit): Fix memory leak. (Forgotten in last commit) * testsuite/gcc.dg/graphite/scop-14.c: New. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/graphite@136623 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog.graphite | 8 ++++++++ gcc/graphite.c | 30 +++++++++++++++++------------- gcc/testsuite/gcc.dg/graphite/scop-14.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/scop-14.c diff --git a/gcc/ChangeLog.graphite b/gcc/ChangeLog.graphite index 002583f724c..3b2c6f8bd38 100644 --- a/gcc/ChangeLog.graphite +++ b/gcc/ChangeLog.graphite @@ -1,3 +1,11 @@ +2008-06-10 Tobias Grosser + + * graphite.c (is_bb_addable): Fix memory leak, handling of loops + with multiple exits and conditional handling in edge cases. + (is_loop_exit): Fix memory leak. (Forgotten in last commit) + + * testsuite/gcc.dg/graphite/scop-14.c: New. + 2008-06-06 Tobias Grosser Adrien Eliche diff --git a/gcc/graphite.c b/gcc/graphite.c index b05c15cc2d0..54086bf97b6 100644 --- a/gcc/graphite.c +++ b/gcc/graphite.c @@ -705,6 +705,7 @@ is_loop_exit (struct loop *loop, basic_block exit_bb) int i; VEC (edge, heap) *exits; edge e; + bool is_exit = false; if (loop_outer (loop) == NULL) return false; @@ -713,9 +714,11 @@ is_loop_exit (struct loop *loop, basic_block exit_bb) for (i = 0; VEC_iterate (edge, exits, i, e); i++) if (e->dest == exit_bb) - return true; + is_exit = true; - return false; + VEC_free (edge, heap, exits); + + return is_exit; } /* Check if 'pred' is predecessor of 'succ'. */ @@ -797,7 +800,7 @@ is_bb_addable (basic_block bb, struct loop *outermost_loop, bb_simple); for (i = 0; VEC_iterate (edge, exits, i, e); i++) - if (dominated_by_p (CDI_DOMINATORS, e->dest, bb) + if (dominated_by_p (CDI_DOMINATORS, e->dest, e->src) && e->dest->loop_father == loop_outer (loop)) build_scops_1 (e->dest, &tmp_scops, e->dest->loop_father, outermost_loop, last, bb_simple); @@ -806,7 +809,8 @@ is_bb_addable (basic_block bb, struct loop *outermost_loop, *last = NULL; *bb_simple = false; bb_addable = false; - free_scops (tmp_scops); + move_scops (&tmp_scops, scops); + VEC_free (edge, heap, exits); return bb_addable; } @@ -829,13 +833,20 @@ is_bb_addable (basic_block bb, struct loop *outermost_loop, basic_block next_tmp; dom_bb = e->dest; + /* Ignore loop exits. They will be handled after the loop body. */ + if (is_loop_exit (bb->loop_father, dom_bb)) + { + bb_addable = false; + continue; + } + /* Only handle bb dominated by 'bb'. The others will be handled by the bb, that dominates this bb. */ if (!dominated_by_p (CDI_DOMINATORS, dom_bb, bb)) { /* Check, if edge leads direct to the end of this condition. If this is true, the condition stays joinable. */ - if (last_bb) + if (!last_bb) last_bb = dom_bb; if (dom_bb != last_bb) @@ -843,13 +854,6 @@ is_bb_addable (basic_block bb, struct loop *outermost_loop, continue; } - - /* Ignore loop exits. They will be handled after the loop body. */ - if (is_loop_exit (bb->loop_father, dom_bb)) - { - bb_addable = false; - continue; - } /* Ignore edges, which jump forward. */ if (VEC_length (edge, dom_bb->preds) > 1) @@ -857,7 +861,7 @@ is_bb_addable (basic_block bb, struct loop *outermost_loop, /* Check, if edge leads direct to the end of this condition. If this is true, the condition stays joinable. */ - if (last_bb) + if (!last_bb) last_bb = dom_bb; if (dom_bb != last_bb) diff --git a/gcc/testsuite/gcc.dg/graphite/scop-14.c b/gcc/testsuite/gcc.dg/graphite/scop-14.c new file mode 100644 index 00000000000..647a6dbf0c7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/scop-14.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgraphite -fdump-tree-graphite-all" } */ + +void bar (); + +int toto() +{ + int i,j, b; + int a[100]; + + for (j = 0; j <= 20; j++) + { + a[j] = b + i; + + if (j * i == b) + break; + + a[j+b] = b + i; + } + + a[i] = b + 3; + + + return a[b]; +} + +/* { dg-final { scan-tree-dump-times "number of SCoPs: 3" 1 "graphite"} } */ +/* { dg-final { cleanup-tree-dump "graphite" } } */ -- cgit v1.2.3