From patchwork Wed Oct 18 10:56:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 154813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4703021vqb; Wed, 18 Oct 2023 03:56:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3OpkCi5157r4BmtnJLf6bdZ18crXrL7p7GIac+k5klsrYjAvSBlupLKEaQgtR2+0N6UdM X-Received: by 2002:a05:620a:4148:b0:774:3147:425a with SMTP id k8-20020a05620a414800b007743147425amr5388583qko.16.1697626597443; Wed, 18 Oct 2023 03:56:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697626597; cv=pass; d=google.com; s=arc-20160816; b=lHBVwMwpUgrNFitWL6eKRjUMZ1utDigz/tVn632K058/O1Ktennl/Lt8Woq/CBdGc8 1aWa57Vf7il/hU3Lp4ZFxqKH2TR0xLfrGxSjf52TIehnasm99kEj++Jekp3daIFI6SEm 0ag0bwGiOg0V6JuFhBcKwvGN1efdD8ksbA9Ax0BDmc9XH5YMIj81PgTfdgucdDxjDcUz e/UuPMUFGJR7gtkTLi5MFVTM8KGUsSoYyurw6XIZtbBJXbnyUSqXAUN4bdXenDanf9Nq tTkjLA8r9S4sqZIRAAuh3drEvSiNLaibQxWdAwU+XaLFgm6PL+X+wDy57SoYvUXg4RoY 1f1Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :ironport-sdr:arc-filter:dmarc-filter:delivered-to; bh=LC2zywFoOxujb8CA4/eZD6d0rJZNgcINk1rn+tIr5n0=; fh=XQ9637rIYKNluC/ZCoyPS25EpMW1ylftTOW7BMZGdSE=; b=E+pLKn+QRvA66AGnijXPt+EJ6fG0OasHS6uWPw/2NFlencDT6DHBe089S+94RxFcJO YXqI89Pban6oqk2camJe/9jUGCDD40q100tzp9zTUW7Lazgg8MKzZX42aU560K87hmq0 zdNUZhRGdBm8ppFM0QJey5hNO4Kw3Jts9icQJNnoWlZ6KUnA31yXMyozXgr0XBsiO2pr Ze/u2tSO6xYCZqB6OcFDbp/x64MJy2LOVifhN5kI0QmefeK5oh1YOsVh+sBB6IpGMf+j jeFGA1wLclbde/6cvdW8z1Kd8GuM4jT964Nm/blhhrTQHnGNrK0y9DXColma1TAhUvnc 3gXg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w12-20020a05620a424c00b0076799979daasi2447585qko.238.2023.10.18.03.56.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:56:37 -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; arc=pass (i=1); 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 1634C3858288 for ; Wed, 18 Oct 2023 10:56:37 +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 80F113858C5E; Wed, 18 Oct 2023 10:56:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80F113858C5E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 80F113858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.137.180 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697626572; cv=none; b=XYXZIN/XwqCgJcyR8j/wPT63dzF18oHiiIGyymPs0C9iNi9mD4iH/nLQqNYwUXDVHAuQmK1SBTybZ4DjtAHUvGPosfTkg7F7oEhIR/XDMUjEC85CqZsGr6quApjc7tkqma15Fhd0uEhTcZ9XSqU0UTSHeyc0Xus+8bdjb4Purr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697626572; c=relaxed/simple; bh=nBOoeW4wU76fUrr1Hy9NVue1IeDl9HxJZDSRFQILU+o=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=wA7HNptqqIKSPs3KF/MBn1ked5sqvNZqPEA6JRfJJEY1YasvZtwadqn87qy4Cx++ZdEwRkzQJp24BKR3dFVNGM3YpAc26tscPkxki3r4gZyxSP8Fo1GjEWMjpdetDFfoAZWPDXGju7ubxxPTiGKn/xKRBhX1rDF2rUYTSU49cE0= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: fRPms5tKR3GjqizeYAj8nA== X-CSE-MsgGUID: fBbxOk2ASay5ukcPDZuHyQ== X-IronPort-AV: E=Sophos;i="6.03,234,1694764800"; d="diff'?scan'208";a="19984684" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 18 Oct 2023 02:56:08 -0800 IronPort-SDR: ERMm3dQ7rq5D3gM+3EsC0nkR88p3Ei2lIH6wEYeUVs3Slif4/XsIB8Y/XRxqnisETXGqUbtoiN AQu+ugJwbtRnf3bFYKvuTtLqoQmV9np/399U1JYRoRHg7ZN45fl3vzzdu5VLWF8cnRjsPI889B LYP90KyUdGH77htPOec/ho86CIA+iMFwxclT9efXYN7B3GLYxFomBZKfG5CluFXJ978QiqcvLD zCqu9T2uxYCL+G4uYsxMHvtm5+cTS8ZENSD+c0qtkLBfUi/HHpXEjx12AfACtenkibOa65J4Mp KJ4= Message-ID: <8d407d7b-c546-4454-92c1-707ef00f0ba0@codesourcery.com> Date: Wed, 18 Oct 2023 12:56:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [Patch] OpenMP: Avoid ICE with LTO and 'omp allocate (was: [Patch] Fortran: Support OpenMP's 'allocate' directive for stack vars) Content-Language: en-US To: Jakub Jelinek , CC: , Thomas Schwinge References: <457ea120-5cca-48e0-89d6-c3eab4234b61@codesourcery.com> <7f16971c-ff06-4e48-85e2-5b38828b7bc2@codesourcery.com> <87wmvkuwdv.fsf@euler.schwinge.homeip.net> From: Tobias Burnus In-Reply-To: X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) 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, 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780090507430073354 X-GMAIL-MSGID: 1780090507430073354 On 18.10.23 11:36, Jakub Jelinek wrote: > On Wed, Oct 18, 2023 at 11:12:44AM +0200, Thomas Schwinge wrote: >> +FAIL: gfortran.dg/gomp/allocate-13.f90 -O (internal compiler error: tree code 'statement_list' is not supported in LTO streams) > Any references to GENERIC code in clauses etc. should have been gimplified > or cleared during gimplification, we shouldn't support STATEMENT_LIST > in LTO streaming. We only needed the statement list as aid during the gimplify.cc handling of GOMP_alloc/GOMP_free for Fortran. How about just remove_attribute it in that case? As discussed, as DECL_ATTRIBUTE gets added from the left to the DECL_CHAIN, there shouldn't be a problem of introducing shared trees; note that 'omp allocate' itself is added per DECL, i.e. it does not introduce sharing itself, either. Tested with x86-64-gnu-linux. 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: Avoid ICE with LTO and 'omp allocate' gcc/ChangeLog: * gimplify.cc (gimplify_bind_expr): Remove "omp allocate" attribute to avoid that auxillary statement list reaches to LTO. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/allocate-13a.f90: New test. gcc/gimplify.cc | 18 ++++++++----- gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90 | 34 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 9c617c21381..22ff1075abb 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -1426,7 +1426,8 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p) DECL_ATTRIBUTES (v) = tree_cons (get_identifier ("omp allocate var"), build_tree_list (NULL_TREE, t), - DECL_ATTRIBUTES (t)); + remove_attribute ("omp allocate", + DECL_ATTRIBUTES (t))); tmp = build_fold_indirect_ref (v); TREE_THIS_NOTRAP (tmp) = 1; SET_DECL_VALUE_EXPR (t, tmp); @@ -1473,7 +1474,12 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p) at the top, unless an allocator or size expression requires to put it afterward; note that the size is always later in generated code; for strings, no - size expr but still an expr might be available. */ + size expr but still an expr might be available. + As LTO does not handle a statement list, 'sl' has + to be removed; done so by removing the attribute. */ + DECL_ATTRIBUTES (t) + = remove_attribute ("omp allocate", + DECL_ATTRIBUTES (t)); tree sl = TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))); tree_stmt_iterator e = tsi_start (sl); tree needle = NULL_TREE; @@ -1631,16 +1637,14 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p) && !is_global_var (t) && DECL_CONTEXT (t) == current_function_decl) { - tree attr; if (flag_openmp && DECL_HAS_VALUE_EXPR_P (t) && TREE_USED (t) - && ((attr = lookup_attribute ("omp allocate", - DECL_ATTRIBUTES (t))) != NULL_TREE) - && TREE_CHAIN (TREE_VALUE (attr)) == NULL_TREE) + && lookup_attribute ("omp allocate", DECL_ATTRIBUTES (t))) { /* For Fortran, TREE_CHAIN (TREE_VALUE (attr)) is set, which - causes that the GOMP_free call is already added above. */ + causes that the GOMP_free call is already added above; + and "omp allocate" is removed from DECL_ATTRIBUTES. */ tree v = TREE_OPERAND (DECL_VALUE_EXPR (t), 0); tree tmp = builtin_decl_explicit (BUILT_IN_GOMP_FREE); tmp = build_call_expr_loc (end_locus, tmp, 2, v, diff --git a/gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90 b/gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90 new file mode 100644 index 00000000000..4b297cdb4aa --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/allocate-13a.f90 @@ -0,0 +1,34 @@ +! { dg-do compile { target lto } } +! { dg-additional-options "-flto" } + +! Same as allocate-13.f90 but compiled with -flto. + +! This was failing before as the statement list, +! used for placing the GOMP_alloc/GOMP_free leaked +! through to LTO. + +module m + implicit none + !$omp requires dynamic_allocators +contains +subroutine f () + !$omp declare target + integer :: var + !$omp allocate(var) + var = 5 +end + +subroutine h () + !$omp target + !$omp parallel + !$omp single + block + integer :: var2(5) + !$omp allocate(var2) + var2(1) = 7 + end block + !$omp end single + !$omp end parallel + !$omp end target +end +end module