From ba6ee9fc83ea84afad140fe6092109fad187544e Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 10 Apr 2017 11:27:05 +0000 Subject: [PATCH] re PR tree-optimization/80304 (Wrong result with do concurrent) 2017-04-10 Richard Biener PR tree-optimization/80304 * tree-ssa-loop-im.c (ref_indep_loop_p_1): Also recurse for safelen. * gcc.dg/torture/pr80304.c: New testcase. From-SVN: r246803 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr80304.c | 27 ++++++++++++++++++++++++++ gcc/tree-ssa-loop-im.c | 14 ++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr80304.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e763c42603a..b02a8100a40 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-04-10 Richard Biener + + PR tree-optimization/80304 + * tree-ssa-loop-im.c (ref_indep_loop_p_1): Also recurse + for safelen. + 2017-04-10 Nathan Sidwell PR target/79905 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 06ea8f75a9b..d579a09067e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-10 Richard Biener + + PR tree-optimization/80304 + * gcc.dg/torture/pr80304.c: New testcase. + 2017-04-10 Nathan Sidwell PR target/79905 diff --git a/gcc/testsuite/gcc.dg/torture/pr80304.c b/gcc/testsuite/gcc.dg/torture/pr80304.c new file mode 100644 index 00000000000..814f08017c2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr80304.c @@ -0,0 +1,27 @@ +/* { dg-do run } */ + +int __attribute__((pure,noinline,noclone)) foo (int *p) +{ + return *p * 2; +} + +int main() +{ + int k = 0; + int i; +#pragma GCC ivdep + for (k = 0; k < 9;) + { + i = 0; + while (1) + { + k += foo (&i); + if (k > 7) + break; + i++; + } + } + if (k != 12) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index dcd941c6ddb..0d806da2a3e 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2145,9 +2145,21 @@ ref_indep_loop_p_1 (int safelen, struct loop *loop, im_mem_ref *ref, fprintf (dump_file, "\n"); } + /* We need to recurse to properly handle UNANALYZABLE_MEM_ID. */ + struct loop *inner = loop->inner; + while (inner) + { + if (!ref_indep_loop_p_1 (safelen, inner, ref, stored_p, ref_loop)) + { + indep_p = false; + break; + } + inner = inner->next; + } + /* Avoid caching here as safelen depends on context and refs are shared between different contexts. */ - return true; + return indep_p; } else { -- 2.30.2