From patchwork Tue Sep 1 23:22:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 513098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9BB1114018C for ; Wed, 2 Sep 2015 09:23:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=TyIdNtjv; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=FKb6bzq3i9f43VDjS PFsywHPadnPhvbjjLOTmxiQ3JNYt8RxMknWd3hZJzBjYMNcwQ/K4gtKmFhqS6oQR /gk7bYQRMQEIRGBk01KcZq1rhI4PfPp0xLE/Wn9fmvWT0acj/3WT2jJ43YG80/Am vwCmkcb4bQEFgCIA3NbnkVF1CU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=UJV3VH+V9TfVXgsIsuijz2Z q3Xw=; b=TyIdNtjvUZM9GNZFCxMyajLmCZRSgUt0YxiTW69ojUoSP7rp6I9ZzTO XkgczjTvCLsPWkWtvYUfa7q1yLilj3EdoLvUK56otjkCkXrtLaF0bKnkcra6uaul ApKeu4au1iBlgjawRgEd5zx9vIED3cqSKYkxRwBopVpFimMkpnhY= Received: (qmail 49543 invoked by alias); 1 Sep 2015 23:23:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 49531 invoked by uid 89); 1 Sep 2015 23:23:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Sep 2015 23:23:02 +0000 Received: from svr-orw-fem-04.mgc.mentorg.com ([147.34.97.41]) by relay1.mentorg.com with esmtp id 1ZWutI-0006J2-3J from Cesar_Philippidis@mentor.com for gcc-patches@gcc.gnu.org; Tue, 01 Sep 2015 16:23:00 -0700 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.3.224.2; Tue, 1 Sep 2015 16:22:59 -0700 Subject: Re: [gomp4] useless reduction locks and other bug fixes To: "gcc-patches@gcc.gnu.org" References: <55E632DE.9060501@codesourcery.com> CC: Nathan Sidwell From: Cesar Philippidis Message-ID: <55E63353.9090501@mentor.com> Date: Tue, 1 Sep 2015 16:22:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55E632DE.9060501@codesourcery.com> [Attaching patch this time.] On 09/01/2015 04:21 PM, Cesar Philippidis wrote: > This patch teaches lower_oacc_reductions not to generate calls to > GOACC_{UN}LOCK if they aren't any reductions. That situation can happen > when there is a fake gang reduction on a private variable. > > I also found a bug where the lower_rec_input_clauses expects there to be > a data mapping for the reduction variable when there isn't, e.g. for > private/local reduction variables. And I made the nvptx backend aware of > the fact that the lhs of a call to REDUCTION_TEARDOWN may be have been > optimized away for worker reductions too. I have a couple of test cases > for these bugs, but I'll include them with my upcoming auto-independent > loop patch. > > This patch has been committed to gomp-4_0-branch. > > Cesar > 2015-09-01 Cesar Philippidis gcc/ * config/nvptx/nvptx.c (nvptx_goacc_reduction_teardown): Allow lhs to be NULL for worker reductions too. * omp-low.c (lower_rec_input_clauses): Bail out on OpenACC reductions. (lower_oacc_reductions): Use maybe_lookup_decl for private reductions. Don't emit locks for fake private gang reductions. diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index 1b85892..51f2893 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -4229,14 +4229,19 @@ nvptx_goacc_reduction_teardown (gimple call) tree rid = gimple_call_arg (call, 5); gimple_seq seq = NULL; + if (v == NULL) + { + gsi_remove (&gsi, true); + return false; + } + push_gimplify_context (true); switch (loop_dim) { case GOMP_DIM_GANG: case GOMP_DIM_VECTOR: - if (v) - gimplify_assign (v, local_var, &seq); + gimplify_assign (v, local_var, &seq); break; case GOMP_DIM_WORKER: { diff --git a/gcc/omp-low.c b/gcc/omp-low.c index fdca880..bfef298 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -3892,7 +3892,14 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist, new_var = var = OMP_CLAUSE_DECL (c); if (c_kind != OMP_CLAUSE_COPYIN) - new_var = lookup_decl (var, ctx); + { + /* Not all OpenACC reductions require new mappings. */ + if (is_gimple_omp_oacc (ctx->stmt) + && (new_var = maybe_lookup_decl (var, ctx)) == NULL) + new_var = var; + else + new_var = lookup_decl (var, ctx); + } if (c_kind == OMP_CLAUSE_SHARED || c_kind == OMP_CLAUSE_COPYIN) { @@ -4724,6 +4731,8 @@ lower_oacc_reductions (enum internal_fn ifn, int loop_dim, tree clauses, tree c, tcode, gwv, rid, lid = build_int_cst (integer_type_node, oacc_lid); int oacc_rid, i; unsigned mask = extract_oacc_loop_mask (ctx); + gimple_seq red_seq = NULL; + int num_reductions = 0; enum tree_code rcode; /* Remove the outer-most level of parallelism from the loop. */ @@ -4753,14 +4762,6 @@ lower_oacc_reductions (enum internal_fn ifn, int loop_dim, tree clauses, gimplify_and_add (call, ilist); } - /* Call GOACC_LOCK. */ - if (ifn == IFN_GOACC_REDUCTION_FINI && write_back) - { - call = build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_GOACC_LOCK, - void_type_node, 2, dim, lid); - gimplify_and_add (call, ilist); - } - for (c = clauses, oacc_rid = 0; c && write_back; c = OMP_CLAUSE_CHAIN (c), oacc_rid++) @@ -4776,7 +4777,9 @@ lower_oacc_reductions (enum internal_fn ifn, int loop_dim, tree clauses, var = OMP_CLAUSE_REDUCTION_PRIVATE_DECL (c); if (var == NULL_TREE) - var = lookup_decl (orig, ctx); + var = maybe_lookup_decl (orig, ctx); + if (var == NULL_TREE) + var = orig; res = build_outer_var_ref (orig, ctx); @@ -4811,16 +4814,32 @@ lower_oacc_reductions (enum internal_fn ifn, int loop_dim, tree clauses, call = build_call_expr_internal_loc (UNKNOWN_LOCATION, ifn, TREE_TYPE (var), 6, ref_to_res, var, gwv, tcode, lid, rid); - gimplify_assign (var, call, ilist); + gimplify_assign (var, call, &red_seq); + num_reductions++; } - /* Call GOACC_UNLOCK. */ - if (ifn == IFN_GOACC_REDUCTION_FINI && write_back) + if (num_reductions) { - dim = build_int_cst (integer_type_node, loop_dim); - call = build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_GOACC_UNLOCK, - void_type_node, 2, dim, lid); - gimplify_and_add (call, ilist); + /* Call GOACC_LOCK. */ + if (ifn == IFN_GOACC_REDUCTION_FINI && write_back) + { + call = build_call_expr_internal_loc (UNKNOWN_LOCATION, + IFN_GOACC_LOCK, void_type_node, + 2, dim, lid); + gimplify_and_add (call, ilist); + } + + gimple_seq_add_seq (ilist, red_seq); + + /* Call GOACC_UNLOCK. */ + 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_UNLOCK, + void_type_node, 2, dim, lid); + gimplify_and_add (call, ilist); + } } }