From patchwork Mon Jul 20 18:35:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1332585 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 4B9Vmc5tCNz9sRN for ; Tue, 21 Jul 2020 04:36:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC47D38618AA; Mon, 20 Jul 2020 18:36:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 131903850419 for ; Mon, 20 Jul 2020 18:36:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 131903850419 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: /rcF45C+lRNfHnoZpgvUb0dpKg+7Tw+iqUr19HI9Txz1vyt+xIioYv2LfOUaU0ElcOqkjGJsXg +c+46Md/+/HlzFf/zmlsuEe0+mtMXWauQGTnpO1KjjXZ4xsQZleangqdP+NnnoV40vfag31RCu wbC1ERrhzAV8C7IqqCIEez4SrV3gJvgWZwWclRi7pwzgIFp+YbtejOe6WFBLce8ypjasfgqYRW RkBCLKHnP1yn+Cztp/XSsRlinDWlltp+jstkU4y0nY70pvXR8+OIX1/ePl7ZvjIvASSP2HwDL8 EDM= X-IronPort-AV: E=Sophos;i="5.75,375,1589270400"; d="diff'?scan'208";a="51220844" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 20 Jul 2020 10:36:08 -0800 IronPort-SDR: U/AUmGpUUHvBXRu1dtiAYcwKtxg2YFVj2YDwPpSgQw5TQ9LI/pfL92cZcPpxWywPrPqCGnB3gY J8TBDy91WooCv7u/gru9GbBAt39zVxjCg+N99fLRKyB1EF5oHoN2+LDMKTAVVinJX5PDMOwhBB TxJFO9Lkh0YNsBZPSLrXIWwWFbs6786SedXIdVdaBfgDw0Yw/u1001eMyJem+/xbsty40/tnQG Xuz/zIjO0dAmkKGfn+HdjnNX5YCVq+yyIR4aAd4dnaT01aLR0DbHqi//Ah1LLVxTv1F1oLxHZy KbM= To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP: Fix tmp-var handling with tree-nested.c [PR93553] Message-ID: Date: Mon, 20 Jul 2020 20:35:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-13.3 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" This is about a PARAM_DECL of a procedure whose internal/nested procedure uses this inside an omp parallel. This leads to the code: D.3940 = x; (*D.3940)[D.3924] = …; And the temporary variable "D.3940" introduced for the nesting was not recorded as DECL for OpenMP, leading to the ICE in scan_omp_1_op as shown in the ICE. This patch adds those temporary variables as PRIVATE to the clause – fixing the ICE. OK for the trunk? Tobias PS: For other other variables, that's done with gimplify.c which adds it to the splay_tree, hence, this issue only occurs if the variable is added later – as here for tree-nested.c. The new code is also used for some C OpenMP/OpenACC testcases in the testsuite, but seemingly it works either way. Interestingly, I do not see any 'private' in the dump for the new testcase – seemingly, it gets optimized away. PPS: Thanks for Jakub for some suggestions! ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter OpenMP: Fix tmp-var handling with tree-nested.c [PR93553] gcc/ChangeLog: PR fortran/93553 * tree-nested.c (omp_new_clauses): New global var. (convert_nonlocal_reference_op): Add init_tmp_var/init_tmp_var vars to it. (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Add those as 'private' to the OpenMP clause. libgomp/ChangeLog: PR fortran/93553 * testsuite/libgomp.fortran/pr93553.f90: New test. gcc/tree-nested.c | 37 +++++++++++++++++++++++++-- libgomp/testsuite/libgomp.fortran/pr93553.f90 | 21 +++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index 4dc5533be84..8c4dadc9f21 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -111,6 +111,7 @@ struct nesting_info char static_chain_added; }; +static tree omp_new_clauses; /* Iterate over the nesting tree, starting with ROOT, depth first. */ @@ -1068,6 +1069,11 @@ convert_nonlocal_reference_op (tree *tp, int *walk_subtrees, void *data) if (use_pointer_in_frame (t)) { x = init_tmp_var (info, x, &wi->gsi); + tree c = build_omp_clause (DECL_SOURCE_LOCATION (x), + OMP_CLAUSE_PRIVATE); + OMP_CLAUSE_DECL (c) = x; + OMP_CLAUSE_CHAIN (c) = omp_new_clauses; + omp_new_clauses = c; x = build_simple_mem_ref_notrap (x); } } @@ -1078,6 +1084,11 @@ convert_nonlocal_reference_op (tree *tp, int *walk_subtrees, void *data) x = save_tmp_var (info, x, &wi->gsi); else x = init_tmp_var (info, x, &wi->gsi); + tree c = build_omp_clause (DECL_SOURCE_LOCATION (x), + OMP_CLAUSE_PRIVATE); + OMP_CLAUSE_DECL (c) = x; + OMP_CLAUSE_CHAIN (c) = omp_new_clauses; + omp_new_clauses = c; } *tp = x; @@ -1186,15 +1197,18 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) { struct nesting_info *const info = (struct nesting_info *) wi->info; bool need_chain = false, need_stmts = false; - tree clause, decl, *pdecl; + tree clause, last_clause, decl, *pdecl; int dummy; bitmap new_suppress; + tree saved_omp_new_clauses = omp_new_clauses; + omp_new_clauses = NULL_TREE; new_suppress = BITMAP_GGC_ALLOC (); bitmap_copy (new_suppress, info->suppress_expansion); for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause)) { + last_clause = clause; pdecl = NULL; switch (OMP_CLAUSE_CODE (clause)) { @@ -1450,6 +1464,14 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) break; } + + if (omp_new_clauses) + { + gcc_assert (*pclauses); + OMP_CLAUSE_CHAIN (last_clause) = omp_new_clauses; + } + omp_new_clauses = saved_omp_new_clauses; + return need_chain; } @@ -1919,15 +1941,19 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) { struct nesting_info *const info = (struct nesting_info *) wi->info; bool need_frame = false, need_stmts = false; - tree clause, decl, *pdecl; + tree clause, last_clause, decl, *pdecl; int dummy; bitmap new_suppress; + tree saved_omp_new_clauses = omp_new_clauses; + omp_new_clauses = NULL_TREE; + new_suppress = BITMAP_GGC_ALLOC (); bitmap_copy (new_suppress, info->suppress_expansion); for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause)) { + last_clause = clause; pdecl = NULL; switch (OMP_CLAUSE_CODE (clause)) { @@ -2193,6 +2219,13 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) break; } + if (omp_new_clauses) + { + gcc_assert (*pclauses); + OMP_CLAUSE_CHAIN (last_clause) = omp_new_clauses; + } + omp_new_clauses = saved_omp_new_clauses; + return need_frame; } diff --git a/libgomp/testsuite/libgomp.fortran/pr93553.f90 b/libgomp/testsuite/libgomp.fortran/pr93553.f90 new file mode 100644 index 00000000000..5d6f10febed --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/pr93553.f90 @@ -0,0 +1,21 @@ +program p + implicit none + integer :: x(8) = 0 + call sub(x) +end +subroutine sub(x) + implicit none + integer i + integer :: x(8) + integer :: c(8) = [(11*i, i=1,8)] + call s + if (any (x /= c)) stop 1 +contains + subroutine s + integer :: i + !$omp parallel do reduction(+:x) + do i = 1, 8 + x(i) = c(i) + end do + end +end