From patchwork Wed Feb 6 10:41:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 218537 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]) by ozlabs.org (Postfix) with SMTP id 252532C02EA for ; Wed, 6 Feb 2013 21:41:50 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1360752111; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=j7PgHwG9Jj4fk7RNu9xT YZtCo1M=; b=g8kwmCw5OLzGl1EafV+YFsHKXcd+cLFYSQOyfN1bTeJTeHJvxhIB tx2dWe2zy9ffEbeupoGaDXiSJjrsyuq2Xuw7LldYylLapEH50QTEu2AkllyrZf9J /WbNcu4WHNTVRUjUDdbVe8tUUlpSsIZ9AudKxvKhlAtejjLMyo8XLeY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=w+RbrTxQ3GiqeySgsvxpL3zhbvnOTTosACdtkQX1zXf8Mlte/2Rag0UTfDkwq0 63JOJT+YYo8q5Dd12xTZdAL2mRNxejDRFBYYGgRdQE78GPpYhSgvbBjhK9L4z6zC VV1cMO7TTpUDQbEuczabdaph48jY3NhTUyh8nmRdAQWuc=; Received: (qmail 6002 invoked by alias); 6 Feb 2013 10:41:42 -0000 Received: (qmail 5924 invoked by uid 22791); 6 Feb 2013 10:41:41 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Feb 2013 10:41:30 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r16AfUPo011646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 6 Feb 2013 05:41:30 -0500 Received: from zalov.redhat.com (vpn1-5-10.ams2.redhat.com [10.36.5.10]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r16AfS0o000725 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 6 Feb 2013 05:41:29 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r16AfRRO007376; Wed, 6 Feb 2013 11:41:27 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r16AfRxj007375; Wed, 6 Feb 2013 11:41:27 +0100 Date: Wed, 6 Feb 2013 11:41:27 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Richard Henderson Subject: [committed] Fix OpenMP shared clause handling of DECL_BY_REFERENCE RESULT_DECLs/PARM_DECLs (PR middle-end/56217) Message-ID: <20130206104127.GR4385@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! use_pointer_for_field in some cases returns true to avoid copy-in/out, which results in the address of the decl being passed around instead of the decl itself. But for RESULT_DECL or PARM_DECL of REFERENCE_TYPE we generate only copy-in, not copy-out (as references can't change), so there is no point passing it as pointer to the reference to something, the reference can't change, only what it references. Besides this generating better code, making RESULT_DECL of REFERENCE_TYPE addressable and regimplifying it can result in invalid IL. Fixed thusly, tested on x86_64-linux, committed to trunk (4.7 backport will follow later on). 2013-02-06 Jakub Jelinek PR middle-end/56217 * omp-low.c (use_pointer_for_field): Return false if lower_send_shared_vars doesn't generate any copy-out code. * g++.dg/gomp/pr56217.C: New test. * testsuite/libgomp.c++/pr56217.C: New test. Jakub --- gcc/omp-low.c.jj 2013-01-11 09:02:35.000000000 +0100 +++ gcc/omp-low.c 2013-02-06 10:42:19.016346866 +0100 @@ -757,12 +757,20 @@ use_pointer_for_field (tree decl, omp_co if (TREE_ADDRESSABLE (decl)) return true; + /* lower_send_shared_vars only uses copy-in, but not copy-out + for these. */ + if (TREE_READONLY (decl) + || ((TREE_CODE (decl) == RESULT_DECL + || TREE_CODE (decl) == PARM_DECL) + && DECL_BY_REFERENCE (decl))) + return false; + /* Disallow copy-in/out in nested parallel if decl is shared in outer parallel, otherwise each thread could store the shared variable in its own copy-in location, making the variable no longer really shared. */ - if (!TREE_READONLY (decl) && shared_ctx->is_nested) + if (shared_ctx->is_nested) { omp_context *up; @@ -785,11 +793,10 @@ use_pointer_for_field (tree decl, omp_co } } - /* For tasks avoid using copy-in/out, unless they are readonly - (in which case just copy-in is used). As tasks can be + /* For tasks avoid using copy-in/out. As tasks can be deferred or executed in different thread, when GOMP_task returns, the task hasn't necessarily terminated. */ - if (!TREE_READONLY (decl) && is_task_ctx (shared_ctx)) + if (is_task_ctx (shared_ctx)) { tree outer; maybe_mark_addressable_and_ret: --- gcc/testsuite/g++.dg/gomp/pr56217.C.jj 2013-02-06 10:44:19.001660809 +0100 +++ gcc/testsuite/g++.dg/gomp/pr56217.C 2013-02-06 10:45:56.991115914 +0100 @@ -0,0 +1,14 @@ +// PR middle-end/56217 +// { dg-do compile } +// { dg-options "-fopenmp" } + +struct S { int *p; S (); S (S &); }; + +S +foo () +{ + S s; + #pragma omp task shared (s) + s.p = 0; + return s; +} --- libgomp/testsuite/libgomp.c++/pr56217.C.jj 2013-02-06 10:48:10.125404318 +0100 +++ libgomp/testsuite/libgomp.c++/pr56217.C 2013-02-06 11:16:30.000000000 +0100 @@ -0,0 +1,36 @@ +// PR middle-end/56217 +// { dg-do run } +// { dg-options "-std=c++0x" } + +extern "C" void abort (); + +template +struct ptr { + T *p; + ptr () : p () {} + ptr (ptr &) = delete; + ptr (ptr &&o) : p(o) {} + operator T * () { return p; } +}; + +int a[6] = { 100, 101, 102, 103, 104, 105 }; + +static ptr +f () +{ + ptr pt; + #pragma omp task shared (pt) + pt.p = a + 2; + #pragma omp taskwait + return pt; +} + +int +main () +{ + ptr pt; + #pragma omp parallel + #pragma omp single + if (f () != a + 2 || *f () != 102) + abort (); +}