]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix up OpenMP expansion of collapsed loops [PR120564]
authorJakub Jelinek <jakub@redhat.com>
Tue, 25 Nov 2025 09:30:51 +0000 (10:30 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 25 Nov 2025 09:30:51 +0000 (10:30 +0100)
Most of gimple_build_cond_empty callers call just build2 to prepare
condition which is put into GIMPLE_COND, but this one spot has been
using incorrectly fold_build2.  Now the arguments of the *build2 were
already gimplified, but the folding of some conditions can turn say
unsigned_var > INT_MAX into (int) unsigned_var < 0 etc. and thus
turn the condition into something invalid in gimple, because we only
try to regimplify the operands if they refer to some decl which needs
to be regimplified (has DECL_VALUE_EXPR on it).

Fixed by also using build2 instead of fold_build2.

2025-11-25  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/120564
* omp-expand.cc (extract_omp_for_update_vars): Use build2 instead of
fold_build2 to build argument for gimple_build_cond_empty.

* c-c++-common/gomp/pr120564.c: New test.

gcc/omp-expand.cc
gcc/testsuite/c-c++-common/gomp/pr120564.c [new file with mode: 0644]

index 385fe1cc88705ee8afde8ba17e5864ec3677f010..6acfd83411871991998d32b1ce6de0d8c9a9864c 100644 (file)
@@ -3299,7 +3299,7 @@ extract_omp_for_update_vars (struct omp_for_data *fd, tree *nonrect_bounds,
          if (DECL_P (v) && TREE_ADDRESSABLE (v))
            v = force_gimple_operand_gsi (&gsi, v, true, NULL_TREE,
                                          false, GSI_CONTINUE_LINKING);
-         t = fold_build2 (fd->loops[i].cond_code, boolean_type_node, v, t);
+         t = build2 (fd->loops[i].cond_code, boolean_type_node, v, t);
          stmt = gimple_build_cond_empty (t);
          gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
          if (walk_tree (gimple_cond_lhs_ptr (as_a <gcond *> (stmt)),
diff --git a/gcc/testsuite/c-c++-common/gomp/pr120564.c b/gcc/testsuite/c-c++-common/gomp/pr120564.c
new file mode 100644 (file)
index 0000000..4dfa4fc
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR middle-end/120564 */
+/* { dg-do compile } */
+
+void bar (unsigned long long, unsigned long long, unsigned long long);
+
+void
+foo (void)
+{
+  unsigned long long v1, v2, v3;
+#pragma omp parallel for schedule(static, 32) collapse(3)
+  for (v1 = 0; v1 < 20; v1 += 2)
+    for (v2 = __LONG_LONG_MAX__; v2 > __LONG_LONG_MAX__; v2 -= 3)
+      for (v3 = 10; v3 > 0; v3--)
+       bar (v1, v2, v3);
+}