From patchwork Tue Oct 18 19:27:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 4303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2124495wrs; Tue, 18 Oct 2022 12:29:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yQ4uDcReclsO274VILrvdG10uCXGrYai+x4VZl7Fm1YsLpEdR3hx8vVHEkyV1umffQBnf X-Received: by 2002:a17:907:9710:b0:791:8aa6:18bb with SMTP id jg16-20020a170907971000b007918aa618bbmr3573631ejc.279.1666121359839; Tue, 18 Oct 2022 12:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666121359; cv=none; d=google.com; s=arc-20160816; b=0qg66IkN4ttJ7P++2G7sm8+yuGp8mDKKDQX92QQIuMeVIP3O//3H6LVJ74EnAhr8ML 5z28J7/+unTztvDjXx2QAOSYzJKee77kxbHnN4+BX0uhcsnQAxrNk88wwRkaJuYfB+A0 uKtuhUwVGNRd6ZkVQ8Yras8ueT2jS71f2ddra/H47gi72WmPF3qoM3Q/+jmysht0DByq JapSa3CRbKmdQydj0QILhomDwIaUykFYBytI3Kcn753hcMLadFq4MX+jBzinkZD02a2Z 5RQEMNa+wG0pcEv8Dr9ReUQPYPo1WR/T900y0pbJd3bXRatKjwAs74mIFqCw4vy/avBt FEOA== 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=OoAOyspGoH78Jqcj+5kz3l87bA6NarHwEcEVzEXsh04=; b=nsoZtW0dTJoYMAbYNFNpldcc7amrElvO46DnoKiI5sAn1OupfeCFcOIi0kcal7GA2+ cNVRoufJTN4yk827zX6Jt8Hz/CTwM/lA8n5HifDl8KlBaXM3YmhcysDaZC8YTr72zquu 2LZC+FIvmaxnYIHlrdLoB1z0KVBDhyOuruiUInlc3FgAYCfgFGP5kszQzs21BPUaK12Z jn9JeWDYjtmgISNx12waKcmn5KPAYpuu8Wk1X0xqhPFZx7ydGsWakLtZK5h9LOvGH7LE jKFsCZYv8iw6PIfgg+SPp/V7oa08yfbp3pWZ5Gkuwnfsz0nUDFAT/WfsN0Jr9aMobaU2 8SGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hp7-20020a1709073e0700b00780ec98afafsi12293171ejc.113.2022.10.18.12.29.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 12:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 F375838582A6 for ; Tue, 18 Oct 2022 19:29:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 8B16C3858D32 for ; Tue, 18 Oct 2022 19:27:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B16C3858D32 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.95,194,1661846400"; d="diff'?scan'208";a="84816464" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 18 Oct 2022 11:27:30 -0800 IronPort-SDR: oWl+HbCCHmhB56vtHDfs2D1FlG8EjqYgD5lizzTX3ZLhwc0wfmTeBtiLDKX1LwmMyk9exu6exW zf/BucZzrxakHD5aUSH7U/fpgOnrsSw+famgM291hs0ocauYc1rpY4vmK8lsBSvszLFGAXYVVp Nna8aCrom1bMND6LkT76CQCQL0D0gi7904wjlpZgmCsoJrDuyC+w93GBxUDGwLxmJTvB2XcGoa AIziAzNOCz0nB4bv5kXcgeM0ifnhmCfF4yI9dtMaoT35FkMlTjeqV4BdwFX5AkDHV/pYh2CsSH mqI= Message-ID: <9e2d0331-92c4-c8a6-a662-61f298fb3976@codesourcery.com> Date: Tue, 18 Oct 2022 21:27:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP: Fix reverse offload GOMP_TARGET_REV IFN corner cases [PR107236] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 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.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?1747054870852696898?= X-GMAIL-MSGID: =?utf-8?q?1747054870852696898?= Found when playing around with reverse offload once I used 'omp target parallel'. The other issue showed up when running the testsuite (which is done with -O2). In all cases, the ICE is in expand_GOMP_TARGET_REV of this IFN, which should be unreachable Note: ENABLE_OFFLOADING inside the compiler must evaluate to true to show up as ICE - otherwise, the IFN is not even generated. I did not see a good reason for DECL_CONTEXT = NULL, thus, I now set it to the same as was set for child_fn - for no good reason. Tested on x86-64 with ENABLE_OFFLOADING albeit without true offloading. 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: Fix reverse offload GOMP_TARGET_REV IFN corner cases [PR107236] For 'target parallel' and similarly nested directives, cgraph_node's calls_declare_variant_alt was not set in the parent region node but in cfun->decl. Hence, pass_omp_device_lower did not process handle the internal function GOMP_TARGET_REV. - Solution is to set it to the DECL_CONTEXT, which is set in adjust_context_and_scope. The cgraph_node::create_clone issue is exposed with -O2 for the existing libgomp.fortran/reverse-offload-1.f90. omp-offload.cc PR middle-end/107236 gcc/ChangeLog: * omp-expand.cc (expand_omp_target): Set calls_declare_variant_alt in DECL_CONTEXT and not to cfun->decl. * cgraphclones.cc (cgraph_node::create_clone): Copy also the node's calls_declare_variant_alt value. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/target-device-ancestor-6.f90: New test. gcc/cgraphclones.cc | 1 + gcc/omp-expand.cc | 13 ++++++------- .../gfortran.dg/gomp/target-device-ancestor-6.f90 | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc index eb0fa87b554..bb4b3c5407d 100644 --- a/gcc/cgraphclones.cc +++ b/gcc/cgraphclones.cc @@ -375,6 +375,7 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count, if (!new_inlined_to) prof_count = count.combine_with_ipa_count (prof_count); new_node->count = prof_count; + new_node->calls_declare_variant_alt = this->calls_declare_variant_alt; /* Update IPA profile. Local profiles need no updating in original. */ if (update_original) diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc index 5dc0bf16e17..c636a174e36 100644 --- a/gcc/omp-expand.cc +++ b/gcc/omp-expand.cc @@ -10054,13 +10054,8 @@ expand_omp_target (struct omp_region *region) /* Handle the case that an inner ancestor:1 target is called by an outer target region. */ - if (!is_ancestor) - cgraph_node::get (child_fn)->calls_declare_variant_alt - |= cgraph_node::get (cfun->decl)->calls_declare_variant_alt; - else /* Duplicate function to create empty nonhost variant. */ + if (is_ancestor) { - /* Enable pass_omp_device_lower pass. */ - cgraph_node::get (cfun->decl)->calls_declare_variant_alt = 1; cgraph_node *fn2_node; child_fn2 = build_decl (DECL_SOURCE_LOCATION (child_fn), FUNCTION_DECL, @@ -10074,7 +10069,7 @@ expand_omp_target (struct omp_region *region) TREE_PUBLIC (child_fn2) = 0; DECL_UNINLINABLE (child_fn2) = 1; DECL_EXTERNAL (child_fn2) = 0; - DECL_CONTEXT (child_fn2) = NULL_TREE; + DECL_CONTEXT (child_fn2) = DECL_CONTEXT (child_fn); DECL_INITIAL (child_fn2) = make_node (BLOCK); BLOCK_SUPERCONTEXT (DECL_INITIAL (child_fn2)) = child_fn2; DECL_ATTRIBUTES (child_fn) @@ -10098,6 +10093,10 @@ expand_omp_target (struct omp_region *region) fn2_node->force_output = 1; node->offloadable = 0; + /* Enable pass_omp_device_lower pass. */ + fn2_node = cgraph_node::get (DECL_CONTEXT (child_fn)); + fn2_node->calls_declare_variant_alt = 1; + t = build_decl (DECL_SOURCE_LOCATION (child_fn), RESULT_DECL, NULL_TREE, void_type_node); DECL_ARTIFICIAL (t) = 1; diff --git a/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-6.f90 b/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-6.f90 new file mode 100644 index 00000000000..821e7852e85 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-6.f90 @@ -0,0 +1,17 @@ +! PR middle-end/107236 + +! Did ICE before because IFN .GOMP_TARGET_REV was not +! processed in omp-offload.cc. +! Note: Test required ENABLE_OFFLOADING being true inside GCC. + +implicit none +!$omp requires reverse_offload +!$omp target parallel num_threads(4) + !$omp target device(ancestor:1) + call foo() + !$omp end target +!$omp end target parallel +contains + subroutine foo + end +end