On Mon, 10 Apr 2017, Richard Biener wrote: > > The following fixes a fortran testcase involving safelen where > store motion needs to be disabled for unanalyzable refs (we don't > know how to transform them). But the safelen case missed to recurse > (because that's only necessary for unanalyzable mems). > > Bootstrap / regtest on x86_64-unknown-linux-gnu. > > I'll try to come up with a testcase later.
Like this. Richard. 2017-04-10 Richard Biener <rguent...@suse.de> 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. Index: gcc/tree-ssa-loop-im.c =================================================================== --- gcc/tree-ssa-loop-im.c (revision 246797) +++ gcc/tree-ssa-loop-im.c (working copy) @@ -2145,9 +2145,21 @@ ref_indep_loop_p_1 (int safelen, struct 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 { Index: gcc/testsuite/gcc.dg/torture/pr80304.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr80304.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr80304.c (working copy) @@ -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; +}