From patchwork Tue Jan 24 15:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 63625 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 840BC385480C for ; Tue, 24 Jan 2023 15:24:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 1C45D3858421; Tue, 24 Jan 2023 15:24:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C45D3858421 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.97,242,1669104000"; d="diff'?scan'208";a="95573479" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 24 Jan 2023 07:24:13 -0800 IronPort-SDR: qlo0yt3ZLuwy1gtwu4yh7SqrYcTmbS/UrpAJrl1nPmRIX4R2HptY40aGKj+BsTv4tERsmOPq6v iEmIxYkWMNscCpop0XbS4bS9A7C/kxQIfrc82UME/Zs/iRllNPhR+zwVt/LBDtrfgjbaa4T4nm vxXw6zj76xjMIDO/FAUvvGPjWBS7ojUjLHBRjBGfe0ARdFZvoYXmD/tCb3YlYkxUm1XVwV/EDa lqsutIIsnYrujlk7qzM6lt1aFk8EHxRLpMYH9CqoEIB6MzOg3ntb0fKRd+5IdUJn0FBWVqDyo4 OQM= Message-ID: Date: Tue, 24 Jan 2023 16:24:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: Jakub Jelinek , gcc-patches CC: fortran From: Tobias Burnus Subject: [Patch] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" I stumbled over a new FAIL (regression) in sollve_vv today, which was due to an odd corner case (see commit log for a description). The mentioned in-scan error is tested for in gomp/loop-2.f90 ("'inscan' REDUCTION clause on construct other than DO, SIMD, DO SIMD, PARALLEL DO, PARALLEL DO SIMD"). I hope that this patch covers all cases and no other surprises exist... OK for mainline? * * * The ICE is new in GCC 13 due to the duplicate diagnostic (cf. PR); the original issue existed before but seemingly did not affect the code, at least the sollve_vv testcase passed before. Still, it could be backported to GCC 12. (Fortran '!$omp loop' support was added with r12-1206.) Thoughts? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] For 'parallel', loop-iteration variables are marked are marked as 'private', unless they either appear in an omp do/simd loop or an data-sharing clause already exists for those on 'parallel'. 'omp loop' wasn't handled, leading to (potentially) multiple data-sharing clauses in gfc_resolve_do_iterator as omp_current_ctx pointed to the 'parallel' directive, ignoring the in-betwen 'loop' directive. The latter lead to a bogus diagnostic - or rather an ICE as the source location var contained only '\0'. gcc/fortran/ChangeLog: PR fortran/108512 * openmp.cc (gfc_resolve_omp_do_blocks): Don't check 'inscan' restrictions for loop as rejected elsewhere. (gfc_resolve_do_iterator): Set a source location for added 'private'-clause arguments. * resolve.cc (gfc_resolve_code): Call gfc_resolve_omp_do_blocks also for EXEC_OMP_LOOP. gcc/testsuite/ChangeLog: PR fortran/108512 * gfortran.dg/gomp/loop-5.f90: New test. gcc/fortran/openmp.cc | 5 +- gcc/fortran/resolve.cc | 1 + gcc/testsuite/gfortran.dg/gomp/loop-5.f90 | 84 +++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index cc1eab90b8c..7673a52249f 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -9056,7 +9056,9 @@ gfc_resolve_omp_do_blocks (gfc_code *code, gfc_namespace *ns) } if (i < omp_current_do_collapse || omp_current_do_collapse <= 0) omp_current_do_collapse = 1; - if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]) + if (code->op == EXEC_OMP_LOOP) + ; /* Already rejected in resolve_omp_clauses. */ + else if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]) { locus *loc = &code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN]->where; @@ -9224,6 +9226,7 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause) p = gfc_get_omp_namelist (); p->sym = sym; + p->where = omp_current_ctx->code->loc; p->next = omp_clauses->lists[OMP_LIST_PRIVATE]; omp_clauses->lists[OMP_LIST_PRIVATE] = p; } diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 94213cd3cd4..bd2a749776d 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -11950,6 +11950,7 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) case EXEC_OMP_DISTRIBUTE_SIMD: case EXEC_OMP_DO: case EXEC_OMP_DO_SIMD: + case EXEC_OMP_LOOP: case EXEC_OMP_SIMD: case EXEC_OMP_TARGET_SIMD: gfc_resolve_omp_do_blocks (code, ns); diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 new file mode 100644 index 00000000000..1948e782653 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/loop-5.f90 @@ -0,0 +1,84 @@ +! { dg-additional-options "-fdump-tree-original" } +! +! PR fortran/108512 + +! The problem was that the context wasn't reset for the 'LOOP' +! such that the clauses of the loops weren't seen when adding +! PRIVATE clauses. +! +! In the following, only the loop variable of the non-OpenMP loop +! in 'subroutine four' should get a front-end addded PRIVATE clause + +implicit none +integer :: x, a(10), b(10), n + n = 10 + a = -42 + b = [(2*x, x=1,10)] + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:a\\) map\\(tofrom:b\\) map\\(tofrom:x\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel\[\r\n\]" 2 "original" } } +! ^- shows up twice; checked only here. +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(x\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel map(tofrom: a, b, x) + !$omp loop lastprivate(x) + DO x = 1, n + a(x) = a(x) + b(x) + END DO + !$omp end loop + !$omp end target parallel + if (x /= 11) error stop + if (any (a /= [(2*x - 42, x=1,10)])) error stop + call two() + call three() + call four() +end + +subroutine two + implicit none + integer :: ii, mm, arr(10) + mm = 10 + arr = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:arr\\) map\\(tofrom:ii\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel shared\\(ii\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp loop lastprivate\\(ii\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel loop map(tofrom: arr) lastprivate(ii) + DO ii = 1, mm + arr(ii) = arr(ii) + ii + END DO +end + +subroutine three + implicit none + integer :: kk, zz, var(10) + zz = 10 + var = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:var\\)\[\r\n\]" 1 "original" } } +! "#pragma omp parallel\[\r\n\]" - shows up twice, dump checked above +! { dg-final { scan-tree-dump-times "#pragma omp loop\[\r\n\]" 1 "original" } } + + !$omp target parallel loop map(tofrom: var) + DO kk = 1, zz + var(kk) = var(kk) + kk + END DO +end + +subroutine four + implicit none + integer :: jj, qq, dist(10) + qq = 10 + dist = 0 + +! { dg-final { scan-tree-dump-times "#pragma omp target map\\(tofrom:dist\\)\[\r\n\]" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel private\\(jj\\)\[\r\n\]" 1 "original" } } + + !$omp target parallel map(tofrom: dist) + ! *no* '!$omp do/loop/simd' + DO jj = 1, qq + dist(qq) = dist(qq) + qq + END DO + !$omp end target parallel +end