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 C7AFB3856261 for ; Wed, 4 May 2022 12:03:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7AFB3856261 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-344-PXWdVIm3P2CWoNmlVY2RpA-1; Wed, 04 May 2022 08:03:42 -0400 X-MC-Unique: PXWdVIm3P2CWoNmlVY2RpA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA7303C62B67; Wed, 4 May 2022 12:03:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74C4B40D1B9F; Wed, 4 May 2022 12:03:41 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 244C3cWE1694133 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 4 May 2022 14:03:39 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 244C3b4s1694132; Wed, 4 May 2022 14:03:37 +0200 Date: Wed, 4 May 2022 14:03:37 +0200 From: Jakub Jelinek To: Tobias Burnus Cc: gcc-patches , fortran Subject: Re: [Patch] OpenMP: Fix use_device_{addr,ptr} with in-data-sharing arg Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=-10.6 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 04 May 2022 12:03:45 -0000 On Wed, Apr 20, 2022 at 03:19:38PM +0200, Tobias Burnus wrote: > For array-descriptor vars, the descriptor is assigned to a temporary. However, > this failed when the clause's argument was in turn in a data-sharing clause > as the outer context's VALUE_EXPR wasn't used. > > gcc/ChangeLog: > > * omp-low.cc (lower_omp_target): Fix use_device_{addr,ptr} with list > item that is in an outer data-sharing clause. > > libgomp/ChangeLog: > > * testsuite/libgomp.fortran/use_device_addr-5.f90: New test. > > gcc/omp-low.cc | 22 ++-- > .../libgomp.fortran/use_device_addr-5.f90 | 143 +++++++++++++++++++++ > 2 files changed, 156 insertions(+), 9 deletions(-) > > diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc > index bf5779b6543..6e387fd9a61 100644 > --- a/gcc/omp-low.cc > +++ b/gcc/omp-low.cc > @@ -13656,26 +13656,30 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) > new_var = lookup_decl (var, ctx); > new_var = DECL_VALUE_EXPR (new_var); > tree v = new_var; > + tree v2 = var; > + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_PTR > + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_USE_DEVICE_ADDR) > + { > + v2 = maybe_lookup_decl_in_outer_ctx (var, ctx); > + if (DECL_HAS_VALUE_EXPR_P (v2)) > + v2 = DECL_VALUE_EXPR (v2); I don't understand the above 2 lines, why do you need that? Regardless whether v2 has DECL_VALUE_EXPR or not, the type of the DECL_VALUE_EXPR (v2) and v2 should be the same, build_fold_indirect_ref should work on both and then v2 is only used as second operand of gimplify_assign, where the gimplifier makes sure to handle DECL_VALUE_EXPR correctly. I certainly don't see any difference in the *.omplower dump if I comment out the above 2 lines. Otherwise LGTM, so if the 2 lines aren't needed, please also drop the {}s around v2 = maybe_lookup_decl_in_outer_ctx (var, ctx); and reindent. > + } > > if (is_ref) > { > - var = build_fold_indirect_ref (var); > - gimplify_expr (&var, &assign_body, NULL, is_gimple_val, > - fb_rvalue); > - v = create_tmp_var_raw (TREE_TYPE (var), get_name (var)); > + v2 = build_fold_indirect_ref (v2); > + v = create_tmp_var_raw (TREE_TYPE (v2), get_name (var)); > gimple_add_tmp_var (v); > TREE_ADDRESSABLE (v) = 1; > - gimple_seq_add_stmt (&assign_body, > - gimple_build_assign (v, var)); > + gimplify_assign (v, v2, &assign_body); > tree rhs = build_fold_addr_expr (v); > gimple_seq_add_stmt (&assign_body, > gimple_build_assign (new_var, rhs)); > } > else > - gimple_seq_add_stmt (&assign_body, > - gimple_build_assign (new_var, var)); > + gimplify_assign (new_var, v2, &assign_body); > > - tree v2 = lang_hooks.decls.omp_array_data (unshare_expr (v), false); > + v2 = lang_hooks.decls.omp_array_data (unshare_expr (v), false); > gcc_assert (v2); > gimplify_expr (&x, &assign_body, NULL, is_gimple_val, fb_rvalue); > gimple_seq_add_stmt (&assign_body, Jakub