From patchwork Mon Jun 8 10:23:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1305074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49gTrG6j9vz9sRh for ; Mon, 8 Jun 2020 20:24:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D89303851C05; Mon, 8 Jun 2020 10:24:09 +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 5FFB43851C01 for ; Mon, 8 Jun 2020 10:24:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5FFB43851C01 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: UU+xJ6Xnz1v2sl3nEe2yNE7TPyBQiDnPpdSJnCOgfdK4AlGBccO58jTrf+OEL6AIgpLpqAmw5E qwOfokF0TiWrlkf/E01qPj33i6v1LDVj2kvBBA28kZKCfGRZeUq2vEGvrtYG7RdF2lgU/nzpu2 3JAHhO+Y0J3EomBGUTYqGxMYyGCyRDvGKTM03axPo06g6ys17maef80ifR6EjulIUdgIrqUARz 9S1Z/a7cm1r/BCfDfnFhyLwW2S4VBQd4z5bgkzQzi58iYOXUSrII01d8qYa3bWLDutiyOO+FT9 C6Q= X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="diff'?scan'208";a="49559649" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 08 Jun 2020 02:24:05 -0800 IronPort-SDR: U1VM8YSfWRMCcLhfLn8BNR+VwydbPnP/+5eixfISTrWv3rmb7gRD5Umklp4Ep0D6duopuyeri4 5wa21xvjN9bSAgQrQTtZDR+3NO0kv1P5BJ4SfqOwMwb/eg7K/g/gOBiWQw7xZPoPBkwoNBhX50 evz2rsJDteFjNvDgY7GTvsHuZALCgFdO4XTHh0uVd7sS4qWo2I1BrQOKWbGmzEvIwBprK8RtNe I4z0sE7Jmv93XqNBe/GxPRwthPRudiPLEr1FFaLkC6JqQafh8BqfpO5QpMzIZnSddT98sOLvp3 kR4= To: Jakub Jelinek , gcc-patches From: Tobias Burnus Subject: [Patch][RFC] openmp: don't add aritificial const decl to offload table (PRs 94848 + 95551) Message-ID: <59015878-3460-d570-1cb5-debab51a5089@codesourcery.com> Date: Mon, 8 Jun 2020 12:23:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, 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: 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@gcc.gnu.org Sender: "Gcc-patches" In the latest PR95551, the issue came up with a Fortran array constructor ("if ((any (array /= [(-i, i=1, 10)])") used in a target section within a host procedure. The constructor is converted into a static local variable A.10 = [-1, -2, ...] ends up in omp-offload.c's offload_vars. With -O3 optimization, the variable is optimized away on the host side but it is still in the .gnu.offload_vars (→ host_table, target_data), causing link errors. * * * I think there is a wider issue (→PR 95551 and others) regarding the consistency between host and target variables and optimizations, but I wonder why such a variables has to appear at all in the offload_vars table. Hence, I am thinking of the attached patch which does not add TREE_READONLY variables to .gnu.offload_vars; I additionally require TREE_ARTIFICIAL as I am thinking of the case such as Fortran parameter to which one an create a pointer to – which might require the mapping information (is_device_{addr,ptr}). [The question is whether more needs to be excluded, e.g. to exclude virtual tables from the exlusion? For instance by requiring TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL ?] For the test case, with -O3, the variable (A.10.3) is optimized away and seemingly also not streamed out as it also does not appear with -foffload="-O0". Thoughts? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter openmp: don't add aritificial const decl to offload table (PRs 94848 + 95551) gcc/ChangeLog: PR lto/94848 PR middle-end/95551 * lto-cgraph.c (output_offload_tables): Skip readonly aritificial variables. * omp-offload.c (add_decls_addresses_to_decl_constructor, omp_finish_file): Likewise libgomp/ChangeLog: PR lto/94848 PR middle-end/95551 * testsuite/libgomp.fortran/target-var.f90: New test. gcc/lto-cgraph.c | 4 +++ gcc/omp-offload.c | 7 +++++- libgomp/testsuite/libgomp.fortran/target-var.f90 | 32 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c index a671c671fa7..747d44c9f84 100644 --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -1077,6 +1077,10 @@ output_offload_tables (void) for (unsigned i = 0; i < vec_safe_length (offload_vars); i++) { + if (TREE_READONLY ((*offload_vars)[i]) + && DECL_ARTIFICIAL ((*offload_vars)[i])) + continue; + streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, LTO_symtab_variable); lto_output_var_decl_ref (ob->decl_state, ob->main_stream, diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index b2df91a5724..2f6c55d8667 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -125,6 +125,9 @@ add_decls_addresses_to_decl_constructor (vec *v_decls, #endif && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it)); + if (is_var && TREE_READONLY (it) && DECL_ARTIFICIAL (it)) + continue; + tree size = NULL_TREE; if (is_var) size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it)); @@ -341,7 +344,7 @@ omp_finish_file (void) add_decls_addresses_to_decl_constructor (offload_vars, v_v); tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node, - num_vars * 2); + vec_safe_length (v_v)); tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node, num_funcs); SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node)); @@ -381,6 +384,8 @@ omp_finish_file (void) for (unsigned i = 0; i < num_vars; i++) { tree it = (*offload_vars)[i]; + if (TREE_READONLY (it) && DECL_ARTIFICIAL (it)) + continue; #ifdef ACCEL_COMPILER if (DECL_HAS_VALUE_EXPR_P (it) && lookup_attribute ("omp declare target link", diff --git a/libgomp/testsuite/libgomp.fortran/target-var.f90 b/libgomp/testsuite/libgomp.fortran/target-var.f90 new file mode 100644 index 00000000000..5e5ccd47c96 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/target-var.f90 @@ -0,0 +1,32 @@ +! { dg-additional-options "-O3" } +! +! With -O3 the static local variable A.10 generated for +! the array constructor [-2, -4, ..., -20] is optimized +! away - which has to be handled in the offload_vars table. +! +program main + implicit none (type, external) + integer :: j + integer, allocatable :: A(:) + + A = [(3*j, j=1, 10)] + call bar (A) + deallocate (A) +contains + subroutine bar (array) + integer :: i + integer :: array(:) + + !$omp target map(from:array) + !$acc parallel copyout(array) + array = [(-2*i, i = 1, size(array))] + !$omp do private(array) + !$acc loop gang private(array) + do i = 1, 10 + array(i) = 9*i + end do + if (any (array /= [(-2*i, i = 1, 10)])) error stop 2 + !$omp end target + !$acc end parallel + end subroutine bar +end