]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/101280 - revise interchange fix for PR101173
authorRichard Biener <rguenther@suse.de>
Thu, 1 Jul 2021 10:49:45 +0000 (12:49 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 1 Jul 2021 11:38:59 +0000 (13:38 +0200)
The following revises the original fix for PR101173 to correctly
check for a reversed dependence rather than disallowing a zero
distance.  It also adds a check from TSVC which asks for this
kind of interchange (but with a valid dependence).

2021-07-01  Richard Biener  <rguenther@suse.de>

PR tree-optimization/101280
PR tree-optimization/101173
* gimple-loop-interchange.cc
(tree_loop_interchange::valid_data_dependences): Revert
previous change and instead correctly handle DDR_REVERSED_P
dependence.

* gcc.dg/tree-ssa/loop-interchange-16.c: New testcase.

gcc/gimple-loop-interchange.cc
gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c [new file with mode: 0644]

index 43045c5455e3606affcb4d8fe2f21c1dae6bce17..43ef112a2d0dd7566b9b0e59c9fb5485516dbaf1 100644 (file)
@@ -1043,8 +1043,11 @@ tree_loop_interchange::valid_data_dependences (unsigned i_idx, unsigned o_idx,
            continue;
 
          /* Be conservative, skip case if either direction at i_idx/o_idx
-            levels is not '=' (for the inner loop) or '<'.  */
-         if (dist_vect[i_idx] < 0 || dist_vect[o_idx] <= 0)
+            levels is not '=' or '<'.  */
+         if (dist_vect[i_idx] < 0
+             || (DDR_REVERSED_P (ddr) && dist_vect[i_idx] > 0)
+             || dist_vect[o_idx] < 0
+             || (DDR_REVERSED_P (ddr) && dist_vect[o_idx] > 0))
            return false;
        }
     }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c
new file mode 100644 (file)
index 0000000..781555e
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR/101280 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-linterchange-details" } */
+
+void dummy (double *, double *);
+#define LEN_2D 32
+double aa[LEN_2D][LEN_2D], bb[LEN_2D][LEN_2D];
+double s231(int iterations)
+{
+//    loop interchange
+//    loop with data dependency
+    for (int nl = 0; nl < 100*(iterations/LEN_2D); nl++) {
+        for (int i = 0; i < LEN_2D; ++i) {
+            for (int j = 1; j < LEN_2D; j++) {
+                aa[j][i] = aa[j - 1][i] + bb[j][i];
+            }
+        }
+        dummy(aa[0],bb[0]);
+    }
+}
+
+/* { dg-final { scan-tree-dump "loops interchanged" "linterchange" } } */