public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10548] tree-optimization/103361 - fix unroll-and-jam direction vector handling
Date: Thu, 21 Apr 2022 12:51:58 +0000 (GMT)	[thread overview]
Message-ID: <20220421125158.D9F6F380DBF8@sourceware.org> (raw)

https://gcc.gnu.org/g:4ed8728e2646897c98826cf43be2e4682d04fc2c

commit r10-10548-g4ed8728e2646897c98826cf43be2e4682d04fc2c
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Nov 23 10:11:41 2021 +0100

    tree-optimization/103361 - fix unroll-and-jam direction vector handling
    
    This properly uses lambda_int instead of truncating the direction
    vector to int which leads to false unexpected negative values.
    
    2021-11-23  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/103361
            * gimple-loop-jam.c (adjust_unroll_factor): Use lambda_int
            for the dependence distance.
            * tree-data-ref.c (print_lambda_vector): Properly print a lambda_int.
    
            * g++.dg/torture/pr103361.C: New testcase.
    
    (cherry picked from commit 6cd440670078af89d82cbb67e01a5ecec8eec238)

Diff:
---
 gcc/gimple-loop-jam.c                   |  4 ++--
 gcc/testsuite/g++.dg/torture/pr103361.C | 18 ++++++++++++++++++
 gcc/tree-data-ref.c                     |  2 +-
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-loop-jam.c b/gcc/gimple-loop-jam.c
index 58d265ea886..bdf818cd333 100644
--- a/gcc/gimple-loop-jam.c
+++ b/gcc/gimple-loop-jam.c
@@ -403,10 +403,10 @@ adjust_unroll_factor (class loop *inner, struct data_dependence_relation *ddr,
 	     a >= N, or b > 0, or b is zero and a > 0.  Otherwise the unroll
 	     factor needs to be limited so that the first condition holds.
 	     That may limit the factor down to zero in the worst case.  */
-	  int dist = dist_v[0];
+	  lambda_int dist = dist_v[0];
 	  if (dist < 0)
 	    gcc_unreachable ();
-	  else if ((unsigned)dist >= *unroll)
+	  else if (dist >= (lambda_int)*unroll)
 	    ;
 	  else if (lambda_vector_zerop (dist_v + 1, DDR_NB_LOOPS (ddr) - 1))
 	    {
diff --git a/gcc/testsuite/g++.dg/torture/pr103361.C b/gcc/testsuite/g++.dg/torture/pr103361.C
new file mode 100644
index 00000000000..ec1d6e1bae4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr103361.C
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-floop-unroll-and-jam" } */
+
+char a, b;
+extern unsigned short c[];
+extern bool d[];
+const unsigned short &e(const unsigned short &f, const unsigned short &g) {
+  if (g < f)
+    return g;
+  return f;
+}
+void k() {
+  for (int h = 0; b; h += 3)
+    for (unsigned long i = 0; i < 11104842004558084287ULL;
+         i += -11104842004558084300ULL)
+      for (bool j(e(6, e(6, c[h + i]))); j < (bool)a; j = 7)
+        d[7] = 0;
+}
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index a0613ed83eb..ba059ebc0de 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -391,7 +391,7 @@ print_lambda_vector (FILE * outfile, lambda_vector vector, int n)
   int i;
 
   for (i = 0; i < n; i++)
-    fprintf (outfile, "%3d ", (int)vector[i]);
+    fprintf (outfile, HOST_WIDE_INT_PRINT_DEC " ", vector[i]);
   fprintf (outfile, "\n");
 }


                 reply	other threads:[~2022-04-21 12:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220421125158.D9F6F380DBF8@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@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).