tree-optimization/103361 - fix unroll-and-jam direction vector handling
authorRichard Biener <rguenther@suse.de>
Tue, 23 Nov 2021 09:11:41 +0000 (10:11 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 23 Nov 2021 10:04:34 +0000 (11:04 +0100)
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.

gcc/gimple-loop-jam.c
gcc/testsuite/g++.dg/torture/pr103361.C [new file with mode: 0644]
gcc/tree-data-ref.c

index 666f740..933a4e0 100644 (file)
@@ -402,10 +402,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 (file)
index 0000000..ec1d6e1
--- /dev/null
@@ -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;
+}
index 46f4ffe..9b6ca1a 100644 (file)
@@ -388,7 +388,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");
 }