]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/90328 (Wrong loop distribution with aliasing)
authorRichard Biener <rguenther@suse.de>
Mon, 6 May 2019 12:38:35 +0000 (12:38 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 6 May 2019 12:38:35 +0000 (12:38 +0000)
2019-05-06  Richard Biener  <rguenther@suse.de>

PR tree-optimization/90328
* tree-data-ref.h (dr_may_alias_p): Pass in the actual loop nest.
* tree-data-ref.c (dr_may_alias_p): Check whether the clique
is valid in the loop nest before using it.
(initialize_data_dependence_relation): Adjust.
* graphite-scop-detection.c (build_alias_set): Pass the SCOP enclosing
loop as loop-nest to dr_may_alias_p.

* gcc.dg/torture/pr90328.c: New testcase.

From-SVN: r270906

gcc/ChangeLog
gcc/graphite-scop-detection.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr90328.c [new file with mode: 0644]
gcc/tree-data-ref.c
gcc/tree-data-ref.h

index 3dae0db7f596f12100b65e095b5dda3e718dba4f..b4424ddd40e3695163b539d76b754db168ce4a0d 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-06  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/90328
+       * tree-data-ref.h (dr_may_alias_p): Pass in the actual loop nest.
+       * tree-data-ref.c (dr_may_alias_p): Check whether the clique
+       is valid in the loop nest before using it.
+       (initialize_data_dependence_relation): Adjust.
+       * graphite-scop-detection.c (build_alias_set): Pass the SCOP enclosing
+       loop as loop-nest to dr_may_alias_p.
+
 2019-05-06  Richard Biener  <rguenther@suse.de>
 
        * dwarf2out.c (mem_loc_descriptor): Initialize int_mode.
index 45f459a3b783d3ec034ac5f2ef606999fc41bfe8..4534d43721f466b497b18f7c1038bfc6803a2df5 100644 (file)
@@ -1417,9 +1417,13 @@ build_alias_set (scop_p scop)
   int i, j;
   int *all_vertices;
 
+  struct loop *nest
+    = find_common_loop (scop->scop_info->region.entry->dest->loop_father,
+                       scop->scop_info->region.exit->src->loop_father);
+
   FOR_EACH_VEC_ELT (scop->drs, i, dr1)
     for (j = i+1; scop->drs.iterate (j, &dr2); j++)
-      if (dr_may_alias_p (dr1->dr, dr2->dr, true))
+      if (dr_may_alias_p (dr1->dr, dr2->dr, nest))
        {
          /* Dependences in the same alias set need to be handled
             by just looking at DR_ACCESS_FNs.  */
index 1dec62f5d9718022e153fa91066f294721703ce6..2ad2c4ac4ce4689a3cf034cd6555049051183ad7 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-06  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/90328
+       * gcc.dg/torture/pr90328.c: New testcase.
+
 2019-05-06  Richard Biener  <rguenther@suse.de>
 
        PR testsuite/90331
diff --git a/gcc/testsuite/gcc.dg/torture/pr90328.c b/gcc/testsuite/gcc.dg/torture/pr90328.c
new file mode 100644 (file)
index 0000000..a70f3dd
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+void g(int*__restrict x, int*y)
+{
+  *x = *y;
+}
+
+void __attribute__((noipa)) f(int* a,int* b)
+{
+  for(int i=0;i<1024;++i)
+    g(a+i,b+i);
+}
+
+int main()
+{
+  int x[1025];
+  for (int i = 0; i < 1025; ++i)
+    x[i] = i+1;
+  f(x+1, x);
+  for (int i = 0; i < 1025; ++i)
+    if (x[i] != 1)
+      __builtin_abort ();
+  return 0;
+}
index 6c69f77e653ee36f894394b6902963e19458749a..67b960d5c6d945d2b44f2a158fdc93c24eef3c09 100644 (file)
@@ -2231,7 +2231,7 @@ object_address_invariant_in_loop_p (const struct loop *loop, const_tree obj)
 
 bool
 dr_may_alias_p (const struct data_reference *a, const struct data_reference *b,
-               bool loop_nest)
+               struct loop *loop_nest)
 {
   tree addr_a = DR_BASE_OBJECT (a);
   tree addr_b = DR_BASE_OBJECT (b);
@@ -2255,6 +2255,11 @@ dr_may_alias_p (const struct data_reference *a, const struct data_reference *b,
 
   if ((TREE_CODE (addr_a) == MEM_REF || TREE_CODE (addr_a) == TARGET_MEM_REF)
       && (TREE_CODE (addr_b) == MEM_REF || TREE_CODE (addr_b) == TARGET_MEM_REF)
+      /* For cross-iteration dependences the cliques must be valid for the
+        whole loop, not just individual iterations.  */
+      && (!loop_nest
+         || MR_DEPENDENCE_CLIQUE (addr_a) == 1
+         || MR_DEPENDENCE_CLIQUE (addr_a) == loop_nest->owned_clique)
       && MR_DEPENDENCE_CLIQUE (addr_a) == MR_DEPENDENCE_CLIQUE (addr_b)
       && MR_DEPENDENCE_BASE (addr_a) != MR_DEPENDENCE_BASE (addr_b))
     return false;
@@ -2366,7 +2371,7 @@ initialize_data_dependence_relation (struct data_reference *a,
     }
 
   /* If the data references do not alias, then they are independent.  */
-  if (!dr_may_alias_p (a, b, loop_nest.exists ()))
+  if (!dr_may_alias_p (a, b, loop_nest.exists () ? loop_nest[0] : NULL))
     {
       DDR_ARE_DEPENDENT (res) = chrec_known;
       return res;
index ab44d07273122a462b885fdb10041f6c89e293f9..69d5a82c56464678330fd1a36d9692185b65b38f 100644 (file)
@@ -473,7 +473,7 @@ dr_alignment (data_reference *dr)
 }
 
 extern bool dr_may_alias_p (const struct data_reference *,
-                           const struct data_reference *, bool);
+                           const struct data_reference *, struct loop *);
 extern bool dr_equal_offsets_p (struct data_reference *,
                                 struct data_reference *);