diff mbox series

[committed] openmp: Don't call omp_finish_clause on implicitly added private clauses on simd [PR102492]

Message ID 20210928094349.GW304296@tucnak
State New
Headers show
Series [committed] openmp: Don't call omp_finish_clause on implicitly added private clauses on simd [PR102492] | expand

Commit Message

Jakub Jelinek Sept. 28, 2021, 9:43 a.m. UTC
Hi!

The gimplifier adds implicit private clauses on SIMD constructs for local
variables in the SIMD body if they are addressable to make sure they use
the magic arrays with "omp simd array" attribute (such that each SIMD lane
has its own copy), but we actually don't need to default privatize etc. those,
the construction for them is done in the SIMD body and so is destruction.
omp_finish_clause for C++ now requires default constructor (and dtor) for private,
so that OpenMP 5.1 default(private) works, but that will never be needed on
SIMD.  So, this patch just doesn't call omp_finish_clause for private on simd.
The C and Fortran langhooks don't do anything for private.

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

2021-09-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/102492
	* gimplify.c (gimplify_adjust_omp_clauses_1): Don't call the
	omp_finish_clause langhook on implicitly added OMP_CLAUSE_PRIVATE
	clauses on SIMD constructs.

	* g++.dg/gomp/simd-3.C: New test.


	Jakub
diff mbox series

Patch

--- gcc/gimplify.c.jj	2021-09-18 09:47:08.363574453 +0200
+++ gcc/gimplify.c	2021-09-27 15:44:23.855457483 +0200
@@ -10914,8 +10914,12 @@  gimplify_adjust_omp_clauses_1 (splay_tre
   *list_p = clause;
   struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   gimplify_omp_ctxp = ctx->outer_context;
-  lang_hooks.decls.omp_finish_clause (clause, pre_p,
-				      (ctx->region_type & ORT_ACC) != 0);
+  /* Don't call omp_finish_clause on implicitly added OMP_CLAUSE_PRIVATE
+     in simd.  Those are only added for the local vars inside of simd body
+     and they don't need to be e.g. default constructible.  */
+  if (code != OMP_CLAUSE_PRIVATE || ctx->region_type != ORT_SIMD) 
+    lang_hooks.decls.omp_finish_clause (clause, pre_p,
+					(ctx->region_type & ORT_ACC) != 0);
   if (gimplify_omp_ctxp)
     for (; clause != chain; clause = OMP_CLAUSE_CHAIN (clause))
       if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
--- gcc/testsuite/g++.dg/gomp/simd-3.C.jj	2021-09-27 15:46:22.726805435 +0200
+++ gcc/testsuite/g++.dg/gomp/simd-3.C	2021-09-27 15:46:15.124911085 +0200
@@ -0,0 +1,16 @@ 
+// PR middle-end/102492
+// { dg-do compile }
+
+struct S { S (int); };
+void bar (S &);
+
+void
+foo ()
+{
+  #pragma omp simd
+  for (int i = 0; i < 64; i++)
+    {
+      S s = 26;
+      bar (s);
+    }
+}