public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: bin.cheng@linux.alibaba.com
Subject: [PATCH] tree-optimization/101280 - revise interchange fix for PR101173
Date: Thu, 1 Jul 2021 13:38:53 +0200 (CEST)	[thread overview]
Message-ID: <n946306n-o821-668q-66q-96p1qs8533@fhfr.qr> (raw)

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).

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

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                |  7 ++++--
 .../gcc.dg/tree-ssa/loop-interchange-16.c     | 22 +++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c

diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc
index 43045c5455e..43ef112a2d0 100644
--- a/gcc/gimple-loop-interchange.cc
+++ b/gcc/gimple-loop-interchange.cc
@@ -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
index 00000000000..781555e085d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c
@@ -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" } } */
-- 
2.26.2

             reply	other threads:[~2021-07-01 11:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01 11:38 Richard Biener [this message]
2021-07-01 14:49 ` Michael Matz
2021-07-02  6:03   ` Richard Biener
2021-07-02  6:54     ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=n946306n-o821-668q-66q-96p1qs8533@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=bin.cheng@linux.alibaba.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).