From patchwork Fri Oct 14 13:38:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 2696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp188629wrs; Fri, 14 Oct 2022 06:40:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM74nS1NJ5oGBMtiQAN34WpdCF+zormBHFAlh7ewwqeOei/rdb6LBf2xztHXqWD4/P/HLRSG X-Received: by 2002:a05:6402:11c9:b0:459:9f7d:6453 with SMTP id j9-20020a05640211c900b004599f7d6453mr4332896edw.372.1665754803038; Fri, 14 Oct 2022 06:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665754803; cv=none; d=google.com; s=arc-20160816; b=di7XjEZyld6O4omhw/pj1oEX+jHgiOFtNLKcbb0oaE7lEfJtOloSUgXt1l4bv53gIA p4vei+4h+2GLQDlYNjBYYYMOaFQUyQSbfdpKTBRMH+AuKCjlqc3Vv4hJ04/D50aFmMTn MrKnFpin6maoqcPURI6CXI/hD+SWbf/x8ye3t4hpVxs272YjIXW6aosjF4DiCdY2QjQ0 DJWowSF9Dn+E6S7trZHqSD5SLzZtqwUeTO5JC5e4APvjlt5V11n3O/HDQ+Ep6/1g4i2/ ABz8vIpyPm2KKxnbvJYPn7JQwaw9+P/psIlr0VbNIK2n5jRU3/CKkfT/1nl8x6C9YPkt IVOA== 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:content-transfer-encoding :mime-version:message-id:date:subject:to:from:ironport-sdr :dmarc-filter:delivered-to; bh=dRFGxNvAJYd1xJZfDCFmgaY4SYWaFPavb6LGZ2ql1gY=; b=YcbVDwsJ5eZSBGCZWChBjTDJ1X9IAVDj1JnW0O2OJN27pFPaecHQIL2KR8/4YL0NH1 xN7Eln7HGXotwbFO7ugaYPxOgFNmQnbgD9jeI0et8IUlNiWHUIQxI4g3J9NX5eKRrJjo zHZNg6plK9O4mBXW7lxRWEO6zs9PSJINoiD4quTNoJUeadezb5NoXrZ8MG/nVQaxlRw5 z9reVNbZFEOVlKuMWhnJnu5Q9dSmucZUGwP1KzrFQ2EFmtA45l+6xUzgeqSB2+scI4P6 P/l4I5TNxokt6qZ9obq0HR7O2R0fhPzzkpp0pty1+RGEW0opSa/TQyjO6cShaJdPm/vO bQiw== 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 e14-20020a056402190e00b004587e99bcc2si2905978edz.383.2022.10.14.06.40.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 06:40:03 -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 A986E3851155 for ; Fri, 14 Oct 2022 13:39:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 98CB33858C83; Fri, 14 Oct 2022 13:39:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 98CB33858C83 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,184,1661846400"; d="scan'208";a="87526903" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 14 Oct 2022 05:39:10 -0800 IronPort-SDR: BWZKKZtNYpbKPtZYnZGSdpKJafcU0CxBFhelzLjZ1o6fPotXv49xr19VxOXoN2dkTEJ4INK5BD JoUv8RTtA3bLNU8AurKKbodQeAsWm0vst7o3YdAUuwm4rlw4YJMxkd0xQqGMTd5Kb+EonU7/rb Xe/lJRHRCJyXSdI4FBny2JOWCUy1ZlWFXqHi6Cj3udsmiesxozzd9yTPr+IyAn9ImZaIosorpY f+kV2R5NngxoB0kB6tPUDhZ/LBtARsSAxEz4+kO68KSkuftXl9r7gCKFp/lq4R4Wx84fOv9hTG rm8= From: Julian Brown To: , "Stubbs, Andrew" , Subject: [PATCH] [og12] amdgcn: Use FLAT addressing for all functions with pointer arguments Date: Fri, 14 Oct 2022 13:38:55 +0000 Message-ID: <20221014133856.3388109-1-julian@codesourcery.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-11.8 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?1746670508061788577?= X-GMAIL-MSGID: =?utf-8?q?1746670508061788577?= The GCN backend uses a heuristic to determine whether to use FLAT or GLOBAL addressing in a particular (offload) function: namely, if a function takes a pointer-to-scalar parameter, it is assumed that the pointer may refer to "flat scratch" space, and thus FLAT addressing must be used instead of GLOBAL. I came up with this heuristic initially whilst working on support for moving OpenACC gang-private variables into local-data share (scratch) memory. The assumption that only scalar variables would be transformed in that way turned out to be wrong. For example, prior to the next patch in the series, Fortran compiler-generated temporary structures were treated as gang private and moved to LDS space, typically overflowing the region allocated for such variables. That will no longer happen after that patch is applied, but there may be other cases of structs moving to LDS space now or in the future that this patch may be needed for. Tested with offloading to AMD GCN. I will apply shortly (to og12). 2022-10-14 Julian Brown gcc/ * config/gcn/gcn.cc (gcn_detect_incoming_pointer_arg): Any pointer argument forces FLAT addressing mode, not just pointer-to-non-aggregate. --- gcc/ChangeLog.omp | 6 ++++++ gcc/config/gcn/gcn.cc | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index d296eb137e8..ceed4da9799 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,9 @@ +2022-10-14 Julian Brown + + * config/gcn/gcn.cc (gcn_detect_incoming_pointer_arg): Any pointer + argument forces FLAT addressing mode, not just + pointer-to-non-aggregate. + 2022-10-12 Andrew Stubbs * config/gcn/gcn.cc (gcn_expand_builtin_1): Change gcn_full_exec_reg diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc index 1f8d8e19971..b01131c0dc2 100644 --- a/gcc/config/gcn/gcn.cc +++ b/gcc/config/gcn/gcn.cc @@ -2819,10 +2819,14 @@ gcn_arg_partial_bytes (cumulative_args_t cum_v, const function_arg_info &arg) return (NUM_PARM_REGS - cum_num) * regsize; } -/* A normal function which takes a pointer argument (to a scalar) may be - passed a pointer to LDS space (via a high-bits-set aperture), and that only - works with FLAT addressing, not GLOBAL. Force FLAT addressing if the - function has an incoming pointer-to-scalar parameter. */ +/* A normal function which takes a pointer argument may be passed a pointer to + LDS space (via a high-bits-set aperture), and that only works with FLAT + addressing, not GLOBAL. Force FLAT addressing if the function has an + incoming pointer parameter. NOTE: This is a heuristic that works in the + offloading case, but in general, a function might read global pointer + variables, etc. that may refer to LDS space or other special memory areas + not supported by GLOBAL instructions, and then this argument check would not + suffice. */ static void gcn_detect_incoming_pointer_arg (tree fndecl) @@ -2832,8 +2836,7 @@ gcn_detect_incoming_pointer_arg (tree fndecl) for (tree arg = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); arg; arg = TREE_CHAIN (arg)) - if (POINTER_TYPE_P (TREE_VALUE (arg)) - && !AGGREGATE_TYPE_P (TREE_TYPE (TREE_VALUE (arg)))) + if (POINTER_TYPE_P (TREE_VALUE (arg))) cfun->machine->use_flat_addressing = true; }