]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix omp for static schedule loop with pointers [PR97898]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 24 Jan 2026 01:06:14 +0000 (17:06 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 27 Jan 2026 21:21:23 +0000 (13:21 -0800)
When r0-122699-gea3a0fdefa353d was done to fix up handling of
gimple statements in openmp expand, there was one spot which did:
```
if (DECL_P (vback) && TREE_ADDRESSABLE (vback))
  t = force_gimple_operand_gsi (&gsi t, true
```
While other locations did:
```
t = force_gimple_operand_gsi (&gsi t, DECL_P (vback) && TREE_ADDRESSABLE (vback) ...
```

This fixes that one location which fixes up openmp for static scheduling with
a pointer as the induction variable.
Basically with a pointer type, we need to convert the rhs of the POINTER_PLUS
to be the same as size_type and with that conversion, the POINTER_PLUS becomes
an invalid gimple.

I don't think this is a regression but this is a small fix up which has now
shown up twice.

Bootstrapped and tested on x86_64-linux-gnu.

PR middle-end/97898

gcc/ChangeLog:

* omp-expand.cc (expand_omp_for_static_chunk): Don't
conditionalize the call to force_gimple_operand_gsi on DECL_P/TREE_ADDRESSABLE
but rather pass that as the 3rd argument.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/pr97898-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/omp-expand.cc
gcc/testsuite/c-c++-common/gomp/pr97898-1.c [new file with mode: 0644]

index 9864ce4021973a7d22f7810f092f8f6050b46d8e..2b4467cab82000dbe560aee90cc29b89b5e4de83 100644 (file)
@@ -6245,9 +6245,10 @@ expand_omp_for_static_chunk (struct omp_region *region,
            t = fold_build_pointer_plus (vmain, step);
          else
            t = fold_build2 (PLUS_EXPR, type, vmain, step);
-         if (DECL_P (vback) && TREE_ADDRESSABLE (vback))
-           t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
-                                         true, GSI_SAME_STMT);
+         t = force_gimple_operand_gsi (&gsi, t,
+                                       DECL_P (vback)
+                                        && TREE_ADDRESSABLE (vback), NULL_TREE,
+                                       true, GSI_SAME_STMT);
          assign_stmt = gimple_build_assign (vback, t);
          gsi_insert_before (&gsi, assign_stmt, GSI_SAME_STMT);
 
diff --git a/gcc/testsuite/c-c++-common/gomp/pr97898-1.c b/gcc/testsuite/c-c++-common/gomp/pr97898-1.c
new file mode 100644 (file)
index 0000000..f0d5c46
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+/* PR middle-end/97898 */
+
+void f (int n, int *s, int *e)
+{
+  int *i;
+#pragma omp for schedule(static, 2)
+  for (i = s; i < e; i += n);
+}
+