From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 1EC6D3857C4F; Tue, 2 Feb 2021 11:46:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1EC6D3857C4F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: euvjT5AuCtK+N157S2aaEQGF7b1SYN2DzisRQV/FDi3WCqa3KH6bl2q2bAnZ2RBmvXGnY4g1pI bazsnQvP4k41rhQV6DKA3RJOVZozwwRYvGtDUkRI311bUtuWrGtASeImmulapD+d2wAu8iSy82 /B6BLT5kkH+pNu/C2RmTj2sFtkueCtHHz/AK2RhSfrttDnQ+eb5QBtRYWhXtpL//h4rM+kJiIr rRX1WEpDBOTbyG8dSyMPuVRBqCFJXTn+nry/5/G0YcB/xH29vgUUN8+Pq70QrXBRL+vuLccKMO 6Aw= X-IronPort-AV: E=Sophos;i="5.79,394,1602576000"; d="diff'?scan'208";a="59969644" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 02 Feb 2021 03:46:06 -0800 IronPort-SDR: TtIjfww+dq/w3/zLuP7kx4a5wSkOFAbR8fFVbCDAOb7vsAnvFyt+22xNoLZpEhnC+LOCJfA4hn mPlDemdWEcgqLcufqVZuKmAjTOUNtOdJTgYNtiJIIWzMxuBdZQRDK2iD37dya4S9oBhOHjqnov kB/2bqezrDbakAd/UNI30Yd6Cjg6a2doiiUpWNlADWncOp21Cx7fSuda/gDhisKu6DDybcxk92 P90+2Rm5ZSltZVcs3sF32IrBWyFQxWZBOQlmE7LSVR4wvkx6Oc+nxf8ju0om52X3ot0gSW2tke 5Lc= Subject: [Patch] Fortran: Fix Array dependency with local coarrays [PR98913] (was: Re: A question about coarrays and -Warray-temporaries) From: Tobias Burnus To: Thomas Koenig , Jorge D'Elia , Gfortran List , gcc-patches References: <121178681.597.1612108263047.JavaMail.zimbra@intec.unl.edu.ar> <9d298701-38a5-c2c5-1daf-7a2dad754369@netcologne.de> Message-ID: <4fc42e9c-676d-f3fc-57ab-f665a679bfbb@codesourcery.com> Date: Tue, 2 Feb 2021 12:46:00 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------130CC28FC00C32BD79AABF19" Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Feb 2021 11:46:10 -0000 --------------130CC28FC00C32BD79AABF19 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable Hi all, the attached patch now handles -fcoarray=3Dsingle and access to the local image like no coarray access, using the same check a before. Actually, I think we could remove the if (..coarray..) check completely: For 'single', it is like no coarrays; for 'lib' both AA[remote] =3D... and "AA =3D ... AA[remove]" will create a function call and uses already temporaries. I don't know what 'native'/'threads' does =E2=80=93 but either= it the image index is different, then no temporary is needed at all =E2=80=93 = or it is the same (in particular: this_image / not present), but then the noncoarray analysis would work. (Knowing that for i !=3D this_image(), AA and AA[i] =E2=80=93 or i /=3D j f= or AA[i] and AA[j] =E2=80=93 we could further relax the checks, but I don't think th= at that's needed.) Hence: Is the patch OK for the trunk? Or should we completely get rid of if-conditional block? Tobias On 01.02.21 12:52, Tobias Burnus wrote: > On 01.02.21 08:42, Thomas Koenig via Fortran wrote: >>> I have a question with -Warray-temporaries in the test below. >>> With the AA coarray that warning appears in the first loop (on its >>> local part), >>> but not with the BB array with the same task, i.e. [...] >> It seems that dependency checking does not detect that no overlap >> can exist in that case, and so generates a temporary. Probably, >> dependency checking was not updated when coarrays were introduced. >> This is a missed optimization, not a correctness issue. > I have now filled https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98913 ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 M=C3=BCnchen R= egistergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas H= eurung, Frank Th=C3=BCrauf --------------130CC28FC00C32BD79AABF19 Content-Type: text/x-patch; charset="UTF-8"; name="dep-caf.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dep-caf.diff" Fortran: Fix Array dependency with local coarrays [PR98913] gcc/fortran/ChangeLog: PR fortran/98913 * dependency.c (gfc_dep_resolver): Treat local access to coarrays like any array access in dependency analysis. gcc/testsuite/ChangeLog: PR fortran/98913 * gfortran.dg/coarray/array_temporary.f90: New test. gcc/fortran/dependency.c | 11 +++- .../gfortran.dg/coarray/array_temporary.f90 | 74 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c index c9baca80cbc..0de5d093aab 100644 --- a/gcc/fortran/dependency.c +++ b/gcc/fortran/dependency.c @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "dependency.h" #include "constructor.h" #include "arith.h" +#include "options.h" /* static declarations */ /* Enums */ @@ -2143,8 +2144,14 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse, case REF_ARRAY: - /* For now, treat all coarrays as dangerous. */ - if (lref->u.ar.codimen || rref->u.ar.codimen) + /* For now, treat all nonlocal coarrays as dangerous. */ + if (flag_coarray != GFC_FCOARRAY_SINGLE + && ((lref->u.ar.codimen + && lref->u.ar.dimen_type[lref->u.ar.dimen] + != DIMEN_THIS_IMAGE) + || (rref->u.ar.codimen + && lref->u.ar.dimen_type[lref->u.ar.dimen] + != DIMEN_THIS_IMAGE))) return 1; if (ref_same_as_full_array (lref, rref)) diff --git a/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90 b/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90 new file mode 100644 index 00000000000..86460a7c282 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/array_temporary.f90 @@ -0,0 +1,74 @@ +! { dg-do compile } +! { dg-additional-options "-Warray-temporaries" } +! +! PR fortran/98913 +! +! Contributed by Jorge D'Elia +! +! Did create an array temporary for local access to coarray +! (but not for identical noncoarray use). +! + +program test + implicit none + integer, parameter :: iin = kind (1) + integer, parameter :: idp = kind (1.0d0) + real (kind=idp), allocatable :: AA (:,:)[:] + real (kind=idp), allocatable :: BB (:,:) + real (kind=idp), allocatable :: UU (:) + integer (kind=iin) :: nn, n1, n2 + integer (kind=iin) :: j, k, k1 + ! + nn = 5 + n1 = 1 + n2 = 10 + ! + allocate (AA (1:nn,n1:n2)[*]) + allocate (BB (1:nn,n1:n2)) + allocate (UU (1:nn)) + ! + k = 1 + k1 = k + 1 + ! + AA = 1.0_idp + BB = 1.0_idp + UU = 2.0_idp + + ! AA - coarrays + ! No temporary needed: + do j = 1, nn + AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) ! { dg-bogus "Creating array temporary" } + end do + do j = 1, nn + AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1-1:nn-1,j) ! { dg-bogus "Creating array temporary" } + end do + do j = 1, nn + AA (k1:nn,j) = AA (k1:nn,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1+1:nn+1,j) ! { dg-bogus "Creating array temporary" } + end do + + ! But: + do j = 1, nn + AA (k1:nn,j) = AA (k1-1:nn-1,j) - UU (k1:nn) * AA (k,j) - UU(k) * AA (k1+1:nn+1,j) ! { dg-warning "Creating array temporary" } + end do + + ! BB - no coarrays + ! No temporary needed: + do j = 1, nn + BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) ! { dg-bogus "Creating array temporary" } + end do + do j = 1, nn + BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1-1:nn-1,j) ! { dg-bogus "Creating array temporary" } + end do + do j = 1, nn + BB (k1:nn,j) = BB (k1:nn,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1+1:nn+1,j) ! { dg-bogus "Creating array temporary" } + end do + + ! But: + do j = 1, nn + BB (k1:nn,j) = BB (k1-1:nn-1,j) - UU (k1:nn) * BB (k,j) - UU(k) * BB (k1+1:nn+1,j) ! { dg-warning "Creating array temporary" } + end do + + deallocate (AA) + deallocate (BB) + deallocate (UU) +end program test --------------130CC28FC00C32BD79AABF19--