From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C5D0F3858D33 for ; Tue, 31 Jan 2023 11:20:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5D0F3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675164007; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=67/bqfKsZa5YMqXSiW7RIOGU9RMTB2egzdFIwG7Imj4=; b=ZbvRBgll9FloTw0ETJIQJ1gjX19GUfU2sFpWPLjUpI0IVEtiumRWbTvH6ql2FMFeYndbNJ Z3qM1T30FUFnZEeaKRhVA1lJ52qg8wng5ll0ahSy1QYe7KHm8dAL6YdMCYjG9Zvkw9zqt7 wdWnCt8qVVRE84SgP+4sondrEcE58Ac= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-28-Vv6OFXBVPi-C2aKLtW_jvA-1; Tue, 31 Jan 2023 06:20:06 -0500 X-MC-Unique: Vv6OFXBVPi-C2aKLtW_jvA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB22F85A5A3; Tue, 31 Jan 2023 11:20:05 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B5502026D4B; Tue, 31 Jan 2023 11:20:05 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30VBK2oN1045496 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 12:20:03 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30VBK1BZ1045495; Tue, 31 Jan 2023 12:20:01 +0100 Date: Tue, 31 Jan 2023 12:20:01 +0100 From: Jakub Jelinek To: Tobias Burnus Cc: gcc-patches , fortran Subject: Re: [Patch] OpenMP/Fortran: Fix loop-iter var privatization with !$OMP LOOP [PR108512] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Jan 24, 2023 at 04:24:07PM +0100, Tobias Burnus wrote: > 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. */ I don't understand why is this needed. Sure, the vast majority of constructs don't allow reduction(inscan, ...), do we need to list them all? Is EXEC_OMP_LOOP somehow reusing that list for something else? What about EXEC_OMP_*_LOOP? If not, how does that differ say from EXEC_OMP_DISTRIBUTE or EXEC_OMP_TASKLOOP and many others? If it is rejected earlier, then perhaps we should free/clear the list after we diagnose it if it causes harm later. > + 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; > } Ok. > 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); I'm afraid this is needed but insufficient. I think case EXEC_OMP_MASKED_TASKLOOP: case EXEC_OMP_MASKED_TASKLOOP_SIMD: case EXEC_OMP_MASTER_TASKLOOP: case EXEC_OMP_MASTER_TASKLOOP_SIMD: case EXEC_OMP_PARALLEL_LOOP: case EXEC_OMP_TARGET_PARALLEL_LOOP: case EXEC_OMP_TARGET_TEAMS_LOOP: case EXEC_OMP_TARGET_SIMD: case EXEC_OMP_TEAMS_LOOP: should be in the list above (of course alphabetically sorted in between the others) gfc_resolve_omp_parallel_blocks (code, ns); (the non-parallel-workshare one). Went through the c-family/c-omp.cc list in comment above splitting function and checked all appropriate constructs there... > 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 Jakub