Hi!

If the loop body doesn't ever continue, we don't have a bb to insert the
updates.  Fixed by not adding them at all in that case.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2020-12-10  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/98205
        * omp-expand.c (expand_omp_for_generic): Fix up broken_loop handling.

        * c-c++-common/gomp/doacross-4.c: New test.

--- gcc/omp-expand.c.jj 2020-11-27 11:25:04.567490804 +0100
+++ gcc/omp-expand.c    2020-12-09 12:41:39.734730025 +0100
@@ -4304,13 +4304,18 @@ expand_omp_for_generic (struct omp_regio
          gsi = gsi_last_bb (l0_bb);
          expand_omp_build_assign (&gsi, counts[fd->collapse - 1],
                                   istart0, true);
-         gsi = gsi_last_bb (cont_bb);
-         t = fold_build2 (PLUS_EXPR, fd->iter_type, counts[fd->collapse - 1],
-                          build_int_cst (fd->iter_type, 1));
-         expand_omp_build_assign (&gsi, counts[fd->collapse - 1], t);
-         tree aref = build4 (ARRAY_REF, fd->iter_type, counts[fd->ordered],
-                             size_zero_node, NULL_TREE, NULL_TREE);
-         expand_omp_build_assign (&gsi, aref, counts[fd->collapse - 1]);
+         if (cont_bb)
+           {
+             gsi = gsi_last_bb (cont_bb);
+             t = fold_build2 (PLUS_EXPR, fd->iter_type,
+                              counts[fd->collapse - 1],
+                              build_int_cst (fd->iter_type, 1));
+             expand_omp_build_assign (&gsi, counts[fd->collapse - 1], t);
+             tree aref = build4 (ARRAY_REF, fd->iter_type,
+                                 counts[fd->ordered], size_zero_node,
+                                 NULL_TREE, NULL_TREE);
+             expand_omp_build_assign (&gsi, aref, counts[fd->collapse - 1]);
+           }
          t = counts[fd->collapse - 1];
        }
       else if (fd->collapse > 1)
--- gcc/testsuite/c-c++-common/gomp/doacross-4.c.jj     2020-12-09 
13:00:07.295383311 +0100
+++ gcc/testsuite/c-c++-common/gomp/doacross-4.c        2020-12-09 
12:59:28.894811370 +0100
@@ -0,0 +1,30 @@
+/* PR middle-end/98205 */
+
+void baz (int) __attribute__((noreturn));
+
+void
+foo (int n)
+{
+  int i;
+  #pragma omp for ordered(1)
+  for (i = 0; i < 8; i += n)
+    {
+      #pragma omp ordered depend(source)
+      #pragma omp ordered depend(sink: i - 2)
+      baz (i);
+    }
+}
+
+void
+bar (int n)
+{
+  int i, j;
+  #pragma omp for collapse(2) ordered(2)
+  for (i = 0; i < 8; i += n)
+    for (j = 0; j < 8; j += n)
+      {
+        #pragma omp ordered depend(source)
+        #pragma omp ordered depend(sink: i - 2, j + 2)
+        baz (i);
+      }
+}

        Jakub

Reply via email to