]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]
authorJakub Jelinek <jakub@redhat.com>
Thu, 19 Jan 2023 20:22:22 +0000 (21:22 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Thu, 19 Jan 2023 20:22:22 +0000 (21:22 +0100)
expand_omp_for_init_counts was using for the case where collapse(2)
inner loop has init expression dependent on non-constant multiple of
the outer iterator and the condition upper bound expression doesn't
depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
will just return NULL if it can't be folded, we need fold_build1
instead.

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/108459
* omp-expand.cc (expand_omp_for_init_counts): Use fold_build1 rather
than fold_unary for NEGATE_EXPR.

* testsuite/libgomp.c/pr108459.c: New test.

(cherry picked from commit 46644ec99cb355845b23bb1d02775c057ed8ee88)

gcc/ChangeLog.omp
gcc/omp-expand.cc
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.c/pr108459.c [new file with mode: 0644]

index 917bb606a0f98f2e6e81095321e58c73d63b7da8..2d4b75134138607e8963843250213030022b6e34 100644 (file)
@@ -1,3 +1,12 @@
+2023-01-19  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2023-01-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/108459
+       * omp-expand.cc (expand_omp_for_init_counts): Use fold_build1 rather
+       than fold_unary for NEGATE_EXPR.
+
 2023-01-03  Sandra Loosemore  <sandra@codesourcery.com>
 
        Backported from master:
index 37c397089b48e1cdbc14774c5cd8fab7adb54cdf..afe00069a56df97440ed0fdbcf9bfff4027eec9a 100644 (file)
@@ -2009,8 +2009,8 @@ expand_omp_for_init_counts (struct omp_for_data *fd, gimple_stmt_iterator *gsi,
            t = fold_build2 (MINUS_EXPR, itype, unshare_expr (fd->loops[i].m2),
                             unshare_expr (fd->loops[i].m1));
          else if (fd->loops[i].m1)
-           t = fold_unary (NEGATE_EXPR, itype,
-                           unshare_expr (fd->loops[i].m1));
+           t = fold_build1 (NEGATE_EXPR, itype,
+                            unshare_expr (fd->loops[i].m1));
          else
            t = unshare_expr (fd->loops[i].m2);
          tree m2minusm1
index be3c17b4019c93bec4e15fabca0c04ffc44eeecd..629efbc58323bbec442951ae6e0b3b784ca7f38e 100644 (file)
@@ -1,3 +1,11 @@
+2023-01-19  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2023-01-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/108459
+       * testsuite/libgomp.c/pr108459.c: New test.
+
 2023-01-13  Andrew Stubbs  <ams@codesourcery.com>
 
        * usm-allocator.c (ALIGN): Use 128-byte alignment.
diff --git a/libgomp/testsuite/libgomp.c/pr108459.c b/libgomp/testsuite/libgomp.c/pr108459.c
new file mode 100644 (file)
index 0000000..87ce981
--- /dev/null
@@ -0,0 +1,41 @@
+/* PR middle-end/108459 */
+
+char a[17][17];
+
+__attribute__((noipa)) void
+foo (int x, int y)
+{
+  #pragma omp for collapse(2)
+  for (int i = 1; i <= 16; i++)
+    for (int j = i * x + y; j <= 16; j++)
+      a[i][j] = 1;
+}
+
+int
+main ()
+{
+  #pragma omp parallel
+  foo (1, 1);
+  for (int i = 0; i <= 16; i++)
+    for (int j = 0; j <= 16; j++)
+      if (i >= 1 && j >= i + 1)
+       {
+         if (a[i][j] != 1)
+           __builtin_abort ();
+         a[i][j] = 0;
+       }
+      else if (a[i][j])
+       __builtin_abort ();
+  #pragma omp parallel
+  foo (2, -2);
+  for (int i = 0; i <= 16; i++)
+    for (int j = 0; j <= 16; j++)
+      if (i >= 1 && j >= 2 * i - 2)
+       {
+         if (a[i][j] != 1)
+           __builtin_abort ();
+       }
+      else if (a[i][j])
+       __builtin_abort ();
+  return 0;
+}