From patchwork Wed Sep 23 17:57:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 521803 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 80BDB1401AF for ; Thu, 24 Sep 2015 03:57:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LYHCdsPS; 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:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=SnKNavr6eCdul5C+0 DUfurOueD62HfUdatYsrsuIBkamIwHPwJdNwYA40VrESPyJhscImV4IZTQ886h7x 4P3gcKNDDH3inc2v+a57QcuxYy9J8TaRlOS9TpJ1t/pFA0nYbxWRnkEDb5gBDBQG x4ENoxoVV1y2MnN0GW3mDl/cp8= 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:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=tMfI1SV/qyeTuTNAbtHDgFp tddw=; b=LYHCdsPS1Mu6h3ckLj9Z+Wj8GMPXm11ubuR1sYwqQCR1FuqUL8Yj6xU nsn5AUV/688PbN7EdpFDcHiC4xbqKJAcQM9KO4POsWK57P5INiSMONUtE/zPB59i NHOuhOox8iiDmcsqhS/bRw40Rx1JAh7Wo8RKaPxv1EWMfrBfqVv0= Received: (qmail 12223 invoked by alias); 23 Sep 2015 17:57:47 -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 12148 invoked by uid 89); 23 Sep 2015 17:57:46 -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; Wed, 23 Sep 2015 17:57:44 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1ZeoIX-0001Vo-GF from Cesar_Philippidis@mentor.com for gcc-patches@gcc.gnu.org; Wed, 23 Sep 2015 10:57:41 -0700 Received: from [127.0.0.1] (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Wed, 23 Sep 2015 10:57:41 -0700 Subject: Re: [gomp4] remap variables inside gang, worker, vector and collapse clauses To: "gcc-patches@gcc.gnu.org" References: <5602E4A3.9020508@codesourcery.com> From: Cesar Philippidis Message-ID: <5602E814.4000800@codesourcery.com> Date: Wed, 23 Sep 2015 10:57:40 -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: <5602E4A3.9020508@codesourcery.com> On 09/23/2015 10:42 AM, Cesar Philippidis wrote: > I've applied this patch to gomp-4_0-branch. This patch, that is. Cesar 2015-09-23 Cesar Philippidis gcc/ * omp-low.c (lower_omp_for): Remap any variables present in OMP_CLAUSE_GANG, OMP_CLAUSE_WORKER, OMP_CLAUSE_VECTOR and OMP_CLAUSE_COLLAPSE becuase they will be used later by expand_omp_for. libgomp/ * testsuite/libgomp.oacc-c-c++-common/gang-static-2.c: Test if static gang expressions containing variables work. * testsuite/libgomp.oacc-fortran/gang-static-1.f90: Likewise. diff --git a/gcc/omp-low.c b/gcc/omp-low.c index ec76096..3f36b7a 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -11325,6 +11325,35 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx) if (oacc_tail) gimple_seq_add_seq (&body, oacc_tail); + /* Update the variables inside any clauses which may be involved in loop + expansion later on. */ + for (tree c = gimple_omp_for_clauses (stmt); c; c = OMP_CLAUSE_CHAIN (c)) + { + int args; + + switch (OMP_CLAUSE_CODE (c)) + { + default: + args = 0; + break; + case OMP_CLAUSE_GANG: + args = 2; + break; + case OMP_CLAUSE_VECTOR: + case OMP_CLAUSE_WORKER: + case OMP_CLAUSE_COLLAPSE: + args = 1; + break; + } + + for (int i = 0; i < args; i++) + { + tree expr = OMP_CLAUSE_OPERAND (c, i); + if (expr && DECL_P (expr)) + OMP_CLAUSE_OPERAND (c, i) = build_outer_var_ref (expr, ctx); + } + } + pop_gimplify_context (new_stmt); gimple_bind_append_vars (new_stmt, ctx->block_vars); diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/gang-static-2.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/gang-static-2.c index 3a9a508..20a866d 100644 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/gang-static-2.c +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/gang-static-2.c @@ -39,7 +39,7 @@ int main () { int a[N]; - int i; + int i, x; #pragma acc parallel loop gang (static:*) num_gangs (10) for (i = 0; i < 100; i++) @@ -78,5 +78,21 @@ main () test_nonstatic (a, 10); + /* Static arguments with a variable expression. */ + + x = 20; +#pragma acc parallel loop gang (static:0+x) num_gangs (10) + for (i = 0; i < 100; i++) + a[i] = GANG_ID (i); + + test_static (a, 10, 20); + + x = 20; +#pragma acc parallel loop gang (static:x) num_gangs (10) + for (i = 0; i < 100; i++) + a[i] = GANG_ID (i); + + test_static (a, 10, 20); + return 0; } diff --git a/libgomp/testsuite/libgomp.oacc-fortran/gang-static-1.f90 b/libgomp/testsuite/libgomp.oacc-fortran/gang-static-1.f90 index e562535..7d56060 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/gang-static-1.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/gang-static-1.f90 @@ -3,6 +3,7 @@ program main integer, parameter :: n = 100 integer i, a(n), b(n) + integer x do i = 1, n b(i) = i @@ -48,6 +49,23 @@ program main call test (a, b, 20, n) + x = 5 + !$acc parallel loop gang (static:0+x) num_gangs (10) + do i = 1, n + a(i) = b(i) + 5 + end do + !$acc end parallel loop + + call test (a, b, 5, n) + + x = 10 + !$acc parallel loop gang (static:x) num_gangs (10) + do i = 1, n + a(i) = b(i) + 10 + end do + !$acc end parallel loop + + call test (a, b, 10, n) end program main subroutine test (a, b, sarg, n)