From patchwork Tue Feb 28 13:06:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 62478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3001622wrd; Tue, 28 Feb 2023 05:08:03 -0800 (PST) X-Google-Smtp-Source: AK7set+ReUEpoSvV+/Rpx7e6qQU5CnUH2LG/fiSVcX4FABH6gGzOt53l4z4Klm1EnD5/rlEMv3xF X-Received: by 2002:a17:907:2ce2:b0:874:e17e:2526 with SMTP id hz2-20020a1709072ce200b00874e17e2526mr3164857ejc.72.1677589682842; Tue, 28 Feb 2023 05:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677589682; cv=none; d=google.com; s=arc-20160816; b=RfFxanZLUyx7SxjbEJIt5BqF6Wm/PsJkLLSOVJK0GwS//RCPOYsXFVlI7SIlRrINTE pxBjxwls5gWcSEuGYIfGjgyP+deNGnnCRY2Kba3Z1gEwCr+rH/XXgqp+xyIsyWY1NqjT 080yuNLuGLtgDCPUdcNYkbDnjOeOqG2EK15secqlb/XmIF9sMq996FtbW4bjURaKtPvo 8SHhFLH2KrB6zvKGLNfWV7GE+WtDx6HNpOGO2R0v58ekMqPlVOFPEtitguZOT8vv9bmy RFkQ9xNpxnFDZ/zTXfiAw5IvIB1c4EiK4JkiJn+Itc/sAsLza+893RXg1U9ZD4dqcpqt azAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=7j2g6rpm+3dcme6OIjLCBMvrr7mSzhQcpiyD0OYNVns=; b=cTyAfyLRJIIybtIJWgPbZRYdlW/1qmQHyOBsfZz6uVkbrT0yikat0XjtE3hx8+pRlY GGam7P3mwBGzZYg0ifahJLTHHP9iyVz1h95F8xa8Tccgj6Fgv+kd+py12q6QQ615lkOV EksMUso7snxEKwV7bvv4YAheovWfMHZqnFiQlQmDLDm2VqXmy8i/YMV1SVGhO528vohp pTx49kJqGKY80qChAd2FxWEGOKPeHPlqwEPj3wMtPU5DOpFO0m8/JoLPx/2elzJ4D1Yc 9FHt98pyzCeQRV5yDI/TIJdYgArYScgO47zpf84MInM/GfLp/yydrr8WSFlSCc5NvXgx JvMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c5-20020a056402120500b004ad02463b96si10503339edw.108.2023.02.28.05.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 05:08:02 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 323733858033 for ; Tue, 28 Feb 2023 13:07:56 +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 6B99F3858421 for ; Tue, 28 Feb 2023 13:06:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B99F3858421 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.98,221,1673942400"; d="diff'?scan'208";a="99789347" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 28 Feb 2023 05:06:47 -0800 IronPort-SDR: AcpyJxUjMFuYppkovhXDRhhEhhAtl/59t1v3zoV0BWFLE5S+nBmCNIcL67tX/uDEr7C4s8pJu3 zkznMLW43jNnMmvJDuPAMgd5QQ8QXMCC/UjdIFUpsuPPrqBXZSZjfGmETjeoMRmL4f6Bn3ks53 +kxSdkrwzgTzMzaDzQ8Y9FeIEzppg7aLjpSHDViPW6+8vWEGpfZ9s63d1XsJ3Oy7K/1xUBBLwn pycSE56EOye21tlesUo6tRY+XmoJ7bI/a07PE19ZnX+8W8MzE4tM88DdreQfhaII2Ww2J6uGzp 1Kc= Message-ID: <437597e7-a9ee-f6f1-3490-dd4e75ee13de@codesourcery.com> Date: Tue, 28 Feb 2023 14:06:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Content-Language: en-US To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP: Ignore side-effects when finding struct comps [PR108545] 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.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759080279376755464?= X-GMAIL-MSGID: =?utf-8?q?1759080279376755464?= (This is marked as P1 regression) Since the structure handling updates, a hash is now used to find expressions which are identical; unfortunately, this mishandles 'volatile' vars as expressions involving them are not regarded as identical. This leads to spurious *multiple* 'map(struct:x' that later causes an ICE. (For details, see also the PR, https://gcc.gnu.org/PR108545 ) OK for mainline? 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: Ignore side-effects when finding struct comps [PR108545] With volatile, two 'x.data' comp refs aren't regarded as identical, causing that the two items in the first map of map(to:x.a, x.a.data) map(pset: x.a.data) end up in separate 'map(struct:x)', which will cause a later ICE. Solution: Ignore side effects when checking the operands in the hash for being equal. (Do so by creating a variant of tree_operand_hash that calls operand_equal_p with OEP_MATCH_SIDE_EFFECTS.) gcc/ChangeLog: PR middle-end/108545 * gimplify.cc (struct tree_operand_sideeff_hash): New. omp_index_mapping_groups_1, omp_index_mapping_groups, omp_reindex_mapping_groups, omp_mapped_by_containing_struct, omp_tsort_mapping_groups_1, omp_tsort_mapping_groups, oacc_resolve_clause_dependencies, omp_build_struct_sibling_lists, gimplify_scan_omp_clauses): Use tree_operand_sideeff_hash instead of tree_operand_hash. gcc/testsuite/ChangeLog: PR middle-end/108545 * c-c++-common/gomp/map-8.c: New test. * gfortran.dg/gomp/map-9.f90: New test. gcc/gimplify.cc | 55 ++++++++++++++++++++++---------- gcc/testsuite/c-c++-common/gomp/map-8.c | 19 +++++++++++ gcc/testsuite/gfortran.dg/gomp/map-9.f90 | 13 ++++++++ 3 files changed, 70 insertions(+), 17 deletions(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 96845154a92..3c0bb1c987a 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -8958,6 +8958,28 @@ enum omp_tsort_mark { PERMANENT }; +/* Hash for trees based on operand_equal_p. + Like tree_operand_hash but accepts side effects. */ +struct tree_operand_sideeff_hash : ggc_ptr_hash +{ + static inline hashval_t hash (const value_type &); + static inline bool equal (const value_type &, + const compare_type &); +}; + +inline hashval_t +tree_operand_sideeff_hash::hash (const value_type &t) +{ + return iterative_hash_expr (t, 0); +} + +inline bool +tree_operand_sideeff_hash::equal (const value_type &t1, + const compare_type &t2) +{ + return operand_equal_p (t1, t2, OEP_MATCH_SIDE_EFFECTS); +} + /* A group of OMP_CLAUSE_MAP nodes that correspond to a single "map" clause. */ @@ -9400,10 +9422,10 @@ omp_group_base (omp_mapping_group *grp, unsigned int *chained, } /* Given a vector of omp_mapping_groups, build a hash table so we can look up - nodes by tree_operand_hash. */ + nodes by tree_operand_sideeff_hash. */ static void -omp_index_mapping_groups_1 (hash_map *grpmap, vec *groups, tree reindex_sentinel) @@ -9432,7 +9454,6 @@ omp_index_mapping_groups_1 (hash_map * +static hash_map * omp_index_mapping_groups (vec *groups) { - hash_map *grpmap - = new hash_map; + hash_map *grpmap + = new hash_map; omp_index_mapping_groups_1 (grpmap, groups, NULL_TREE); @@ -9502,14 +9523,14 @@ omp_index_mapping_groups (vec *groups) so, we can do the reindex operation in two parts, on the processed and then the unprocessed halves of the list. */ -static hash_map * +static hash_map * omp_reindex_mapping_groups (tree *list_p, vec *groups, vec *processed_groups, tree sentinel) { - hash_map *grpmap - = new hash_map; + hash_map *grpmap + = new hash_map; processed_groups->truncate (0); @@ -9550,7 +9571,7 @@ omp_containing_struct (tree expr) that maps that structure, if present. */ static bool -omp_mapped_by_containing_struct (hash_map *grpmap, tree decl, omp_mapping_group **mapped_by_group) @@ -9590,7 +9611,7 @@ omp_mapped_by_containing_struct (hash_map *groups, - hash_map + hash_map *grpmap, omp_mapping_group *grp) { @@ -9670,7 +9691,7 @@ omp_tsort_mapping_groups_1 (omp_mapping_group ***outlist, static omp_mapping_group * omp_tsort_mapping_groups (vec *groups, - hash_map + hash_map *grpmap) { omp_mapping_group *grp, *outlist = NULL, **cursor; @@ -9986,7 +10007,7 @@ omp_check_mapping_compatibility (location_t loc, void oacc_resolve_clause_dependencies (vec *groups, - hash_map *grpmap) { int i; @@ -10520,8 +10541,8 @@ static bool omp_build_struct_sibling_lists (enum tree_code code, enum omp_region_type region_type, vec *groups, - hash_map - **grpmap, + hash_map **grpmap, tree *list_p) { unsigned i; @@ -10747,7 +10768,7 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, groups = omp_gather_mapping_groups (list_p); if (groups) { - hash_map *grpmap; + hash_map *grpmap; grpmap = omp_index_mapping_groups (groups); omp_build_struct_sibling_lists (code, region_type, groups, &grpmap, @@ -10783,7 +10804,7 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, groups = omp_gather_mapping_groups (list_p); if (groups) { - hash_map *grpmap; + hash_map *grpmap; grpmap = omp_index_mapping_groups (groups); oacc_resolve_clause_dependencies (groups, grpmap); diff --git a/gcc/testsuite/c-c++-common/gomp/map-8.c b/gcc/testsuite/c-c++-common/gomp/map-8.c new file mode 100644 index 00000000000..cc7dac8bd0f --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/map-8.c @@ -0,0 +1,19 @@ +/* { dg-additional-options "-fdump-tree-omplower" } */ + +/* PR fortran/108545 */ + +/* { dg-final { scan-tree-dump "#pragma omp target enter data map\\(struct:my_struct \\\[len: 1\\\]\\) map\\(to:my_struct.u \\\[len: \[0-9\]+\\\]\\)" "omplower" } } */ +/* { dg-final { scan-tree-dump "#pragma omp target enter data map\\(to:my_struct3 \\\[len: \[0-9\]+\\\]\\)" "omplower" } } */ + + +volatile struct t { + struct t2 { int *a; int c; } u; + int b; +} my_struct; +volatile struct t3 { int *a; int c; } my_struct3; + +void f() +{ + #pragma omp target enter data map(to:my_struct.u) map(to:my_struct.u.a) + #pragma omp target enter data map(to:my_struct3) map(to:my_struct3.a) +} diff --git a/gcc/testsuite/gfortran.dg/gomp/map-9.f90 b/gcc/testsuite/gfortran.dg/gomp/map-9.f90 new file mode 100644 index 00000000000..9e7b811c8af --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/map-9.f90 @@ -0,0 +1,13 @@ +! { dg-additional-options "-fdump-tree-omplower" } + +! PR fortran/108545 + +! { dg-final { scan-tree-dump "#pragma omp target enter data map\\(struct:x \\\[len: 1\\\]\\) map\\(to:x.a \\\[len: \[0-9\]+\\\]\\) map\\(to:MEM \\\[\\(integer\\(kind=4\\)\\\[0:\\\] \\*\\)_\[0-9\]+] \\\[len: _\[0-9\]+\\\]\\) map\\(always_pointer:x.a.data \\\[pointer assign, bias: 0\\\]\\)" "omplower" } } + +program p + type t + integer, pointer :: a(:) + end type + type(t), volatile :: x + !$omp target enter data map(to: x%a) +end