re PR tree-optimization/80304 (Wrong result with do concurrent)
authorRichard Biener <rguenther@suse.de>
Mon, 10 Apr 2017 11:27:05 +0000 (11:27 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 10 Apr 2017 11:27:05 +0000 (11:27 +0000)
2017-04-10  Richard Biener  <rguenther@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.

From-SVN: r246803

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr80304.c [new file with mode: 0644]
gcc/tree-ssa-loop-im.c

index e763c42..b02a810 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-10  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/80304
+       * tree-ssa-loop-im.c (ref_indep_loop_p_1): Also recurse
+       for safelen.
+
 2017-04-10  Nathan Sidwell  <nathan@acm.org>
 
        PR target/79905
index 06ea8f7..d579a09 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-10  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/80304
+       * gcc.dg/torture/pr80304.c: New testcase.
+
 2017-04-10  Nathan Sidwell  <nathan@acm.org>
 
        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 (file)
index 0000000..814f080
--- /dev/null
@@ -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;
+}
index dcd941c..0d806da 100644 (file)
@@ -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
     {