This patch teaches omplow how to emit function calls to IFN_GOACC_LOCK_INIT so that the worker mutex has a proper initial value. On nvptx targets, shared memory isn't initialized (and that's where the lock is located for OpenACC workers), so this makes it explicit. Nathan added the internal function used in the patch a couple of days ago.
I've applied this patch to gomp-4_0-branch. Cesar
2015-08-26 Cesar Philippidis <ce...@codesourcery.com> gcc/ * omp-low.c (lower_oacc_reductions): Call GOACC_REDUCTION_INIT to initialize the gang and worker mutex. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 955a098..ee92141 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -4795,10 +4795,20 @@ lower_oacc_reductions (enum internal_fn ifn, int loop_dim, tree clauses, if (ctx->reductions == 0) return; + dim = build_int_cst (integer_type_node, loop_dim); + + /* Call GOACC_LOCK_INIT. */ + if (ifn == IFN_GOACC_REDUCTION_SETUP) + { + call = build_call_expr_internal_loc (UNKNOWN_LOCATION, + IFN_GOACC_LOCK_INIT, + void_type_node, 2, dim, lid); + gimplify_and_add (call, ilist); + } + /* Call GOACC_LOCK. */ if (ifn == IFN_GOACC_REDUCTION_FINI && write_back) { - dim = build_int_cst (integer_type_node, loop_dim); call = build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_GOACC_LOCK, void_type_node, 2, dim, lid); gimplify_and_add (call, ilist);