]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Only apply adjust_args in OpenMP dispatch if variant substitution occurs
authorPaul-Antoine Arras <parras@baylibre.com>
Mon, 6 Jan 2025 16:00:10 +0000 (17:00 +0100)
committerPaul-Antoine Arras <parras@baylibre.com>
Tue, 7 Jan 2025 15:01:44 +0000 (16:01 +0100)
This is a followup to
084ea8ad584 OpenMP: middle-end support for dispatch + adjust_args.

This patch fixes a bug that caused arguments in an OpenMP dispatch call to be
modified even when no variant substitution occurred.

gcc/ChangeLog:

* gimplify.cc (gimplify_call_expr): Create variable
variant_substituted_p to control whether adjust_args applies.

gcc/testsuite/ChangeLog:

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

gcc/gimplify.cc
gcc/testsuite/c-c++-common/gomp/adjust-args-4.c [new file with mode: 0644]

index bd324be926ae3f134c2ee0e0a8f311eaeec0ea90..251d581f44cd6b1bebf6eeb208607719ca96c2c0 100644 (file)
@@ -3857,7 +3857,8 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
   enum gimplify_status ret;
   int i, nargs;
   gcall *call;
-  bool builtin_va_start_p = false, omp_dispatch_p = false;
+  bool builtin_va_start_p = false, omp_dispatch_p = false,
+       variant_substituted_p = false;
   location_t loc = EXPR_LOCATION (*expr_p);
 
   gcc_assert (TREE_CODE (*expr_p) == CALL_EXPR);
@@ -4035,7 +4036,10 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
     {
       tree variant = omp_resolve_declare_variant (fndecl);
       if (variant != fndecl)
-       CALL_EXPR_FN (*expr_p) = build1 (ADDR_EXPR, fnptrtype, variant);
+       {
+         CALL_EXPR_FN (*expr_p) = build1 (ADDR_EXPR, fnptrtype, variant);
+         variant_substituted_p = true;
+       }
     }
 
   /* There is a sequence point before the call, so any side effects in
@@ -4325,8 +4329,9 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
                                }
                            }
 
-                         if ((need_device_ptr && !is_device_ptr)
-                             || (need_device_addr && !has_device_addr))
+                         if (variant_substituted_p
+                             && ((need_device_ptr && !is_device_ptr)
+                                 || (need_device_addr && !has_device_addr)))
                            {
                              if (dispatch_device_num == NULL_TREE)
                                {
diff --git a/gcc/testsuite/c-c++-common/gomp/adjust-args-4.c b/gcc/testsuite/c-c++-common/gomp/adjust-args-4.c
new file mode 100644 (file)
index 0000000..377932e
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-gimple" } */
+
+/* Ensure that adjust_args is only applied when variant substitution happens. */
+
+void h(int *);
+void f(int *);
+#pragma omp declare variant(f) match(construct={dispatch}) adjust_args(need_device_ptr : x)
+void g(int *x);
+
+void foo(int *y)
+{
+  #pragma omp dispatch
+    h(y);
+  #pragma omp dispatch
+    f(y);
+  #pragma omp dispatch
+    g(y);
+}
+
+/* { dg-final { scan-tree-dump-times "h \\(y\\);" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "f \\(y\\);" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "D\.\[0-9]+ = __builtin_omp_get_mapped_ptr \\(y, D\.\[0-9]+\\);" 1 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "f \\(D\.\[0-9]+\\);" 1 "gimple" } } */