middle-end/101009 - fix distance vector recording
authorRichard Biener <rguenther@suse.de>
Fri, 11 Jun 2021 07:33:58 +0000 (09:33 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 11 Jun 2021 09:26:10 +0000 (11:26 +0200)
This fixes recording of distance vectors in case the DDR has just
constant equal indexes.  In that case we expect distance vectors
with zero distances to be recorded which is what was done when
any distance was computed for affine indexes.

2021-06-11  Richard Biener  <rguenther@suse.de>

PR middle-end/101009
* tree-data-ref.c (build_classic_dist_vector_1): Make sure
to set *init_b to true when we encounter a constant equal
index pair.
(compute_affine_dependence): Also dump the actual DR_REF.

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

gcc/testsuite/gcc.dg/torture/pr101009.c [new file with mode: 0644]
gcc/tree-data-ref.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr101009.c b/gcc/testsuite/gcc.dg/torture/pr101009.c
new file mode 100644 (file)
index 0000000..2bbed1d
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fno-tree-sra -fno-tree-pre -ftree-loop-distribution" } */
+
+struct a {
+  unsigned b;
+  unsigned c;
+} e, *f = &e;
+int d = 1;
+int main() {
+  for (; d; d--) {
+    struct a g[] = {{2, 1}, {2, 1}};
+    *f = g[1];
+  }
+  if (e.c != 1)
+    __builtin_abort ();
+  return 0;
+}
index b1f6468..b37c234 100644 (file)
@@ -5121,6 +5121,8 @@ build_classic_dist_vector_1 (struct data_dependence_relation *ddr,
          non_affine_dependence_relation (ddr);
          return false;
        }
+      else
+       *init_b = true;
     }
 
   return true;
@@ -5616,9 +5618,13 @@ compute_affine_dependence (struct data_dependence_relation *ddr,
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
       fprintf (dump_file, "(compute_affine_dependence\n");
-      fprintf (dump_file, "  stmt_a: ");
+      fprintf (dump_file, "  ref_a: ");
+      print_generic_expr (dump_file, DR_REF (dra));
+      fprintf (dump_file, ", stmt_a: ");
       print_gimple_stmt (dump_file, DR_STMT (dra), 0, TDF_SLIM);
-      fprintf (dump_file, "  stmt_b: ");
+      fprintf (dump_file, "  ref_b: ");
+      print_generic_expr (dump_file, DR_REF (drb));
+      fprintf (dump_file, ", stmt_b: ");
       print_gimple_stmt (dump_file, DR_STMT (drb), 0, TDF_SLIM);
     }