From c976786b9787d814baf22e6398fd3fa5c57c558a Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 15 Feb 2012 11:05:26 +0000 Subject: [PATCH] backport: re PR tree-optimization/46886 (wrong code with -ftree-parallelize-loops -fno-tree-ch) 2012-02-15 Richard Guenther Backport from mainline 2012-02-08 Richard Guenther PR tree-optimization/46886 * tree-flow.h (do_while_loop_p): Declare. * tree-ssa-loop-ch.c (do_while_loop_p): Export. * tree-parloops.c (parallelize_loops): Only parallelize do-while loops. * testsuite/libgomp.c/pr46886.c: New testcase. From-SVN: r184263 --- gcc/ChangeLog | 11 +++++++++++ gcc/tree-flow.h | 3 +++ gcc/tree-parloops.c | 5 ++++- gcc/tree-ssa-loop-ch.c | 2 +- libgomp/ChangeLog | 8 ++++++++ libgomp/testsuite/libgomp.c/pr46886.c | 28 +++++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c/pr46886.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 084bb1135c4d..da9520a4bbef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2012-02-15 Richard Guenther + + Backport from mainline + 2012-02-08 Richard Guenther + + PR tree-optimization/46886 + * tree-flow.h (do_while_loop_p): Declare. + * tree-ssa-loop-ch.c (do_while_loop_p): Export. + * tree-parloops.c (parallelize_loops): Only parallelize do-while + loops. + 2012-02-15 Eric Botcazou PR target/51921 diff --git a/gcc/tree-flow.h b/gcc/tree-flow.h index 0777aecae72d..77948cd179a2 100644 --- a/gcc/tree-flow.h +++ b/gcc/tree-flow.h @@ -611,6 +611,9 @@ extern bool may_propagate_copy (tree, tree); extern bool may_propagate_copy_into_stmt (gimple, tree); extern bool may_propagate_copy_into_asm (tree); +/* In tree-ssa-loop-ch.c */ +bool do_while_loop_p (struct loop *); + /* Affine iv. */ typedef struct diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c index 9a11f80d4b01..e9154c37e65c 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -2132,7 +2132,10 @@ parallelize_loops (void) || loop_has_blocks_with_irreducible_flag (loop) || (loop_preheader_edge (loop)->src->flags & BB_IRREDUCIBLE_LOOP) /* FIXME: the check for vector phi nodes could be removed. */ - || loop_has_vector_phi_nodes (loop)) + || loop_has_vector_phi_nodes (loop) + /* FIXME: transform_to_exit_first_loop does not handle not + header-copied loops correctly - see PR46886. */ + || !do_while_loop_p (loop)) continue; estimated = estimated_loop_iterations_int (loop, false); /* FIXME: Bypass this check as graphite doesn't update the diff --git a/gcc/tree-ssa-loop-ch.c b/gcc/tree-ssa-loop-ch.c index c58cb5f8bba5..513745bc2fe9 100644 --- a/gcc/tree-ssa-loop-ch.c +++ b/gcc/tree-ssa-loop-ch.c @@ -104,7 +104,7 @@ should_duplicate_loop_header_p (basic_block header, struct loop *loop, /* Checks whether LOOP is a do-while style loop. */ -static bool +bool do_while_loop_p (struct loop *loop) { gimple stmt = last_stmt (loop->latch); diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index f614c41ba77a..4e681b7e273b 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,11 @@ +2012-02-15 Richard Guenther + + Backport from mainline + 2012-02-08 Richard Guenther + + PR tree-optimization/46886 + * testsuite/libgomp.c/pr46886.c: New testcase. + 2011-11-20 Andreas Tobler * configure: Regenerate. diff --git a/libgomp/testsuite/libgomp.c/pr46886.c b/libgomp/testsuite/libgomp.c/pr46886.c new file mode 100644 index 000000000000..fbdc4e130d31 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr46886.c @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-options "-O -ftree-parallelize-loops=4 -fno-tree-ch -fno-tree-dominator-opts" } */ + +void abort(void); + +int d[1024], e[1024]; + +int foo (void) +{ + int s = 0; + int i; + for (i = 0; i < 1024; i++) + s += d[i] - e[i]; + return s; +} + +int main () +{ + int i; + for (i = 0; i < 1024; i++) + { + d[i] = i * 2; + e[i] = i; + } + if (foo () != 1023 * 1024 / 2) + abort (); + return 0; +} -- 2.47.2