From patchwork Tue Nov 29 13:45:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 27244 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp344478wrr; Tue, 29 Nov 2022 05:46:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5lMWWfJKSnPD80/+iKa+UFFqozkM7R+pL02h05O/NvCDfr2oFRrQiwp3V89DFDCCPuAKeE X-Received: by 2002:a17:906:8e94:b0:7bf:7ac6:69c3 with SMTP id ru20-20020a1709068e9400b007bf7ac669c3mr9992953ejc.621.1669729567973; Tue, 29 Nov 2022 05:46:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669729567; cv=none; d=google.com; s=arc-20160816; b=j0D+Iq2uf/JVCuGHHXbZRDgkbdq7qgrUrCQZmlN7zZcvh81aW+fI2Skr69Mop/9mD3 wvFEyNzjKCAYtq9qm+MdqBhhZp/Nho8S3e5/TDxcA5sy3a0SvicIey9bm8lO8PM3qS+p Uuo2V6mZUnEoEsO2pCMDc9Z5VV9Km9Y8ZxAlp+YwT4njsW3jPKwiTmqHUQWkvwxz0xjZ nufymyKp71xcdGL+91X5K8CekiSgPuSlVOerFcMAKqcAcvMXfV5FNtcyT9zhOeQ/Jrei qcCqUeoNqyb0Itt9lKTV3EoH4Om4x5DKR/CscBLT64v4irXMMWEKDoY1igy//kudpw+Z Ibig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=lMmTzEwUPSaDOnCtfmtbjL6xLJglpZOtvxSojGgtH+k=; b=LTIdPQG2xoP1ihrXZCHHkbbjthLduS7LGPDNzf4IJyKoiZz4ytaZsNfMM4S0onjIFw xpbhBm01N4avOCzC3iqrFAbN6PUN1w9oVRTA25/Vk6CgtTO2s6TbpDJCTVP8zIEb0IZO FzH5WW/ij8e7vvwfeL/8eTcNL0xWJ/O/T8I5iT2WAmTybaCg4tqJvvaIDjVoWrjSbzI4 m7ch1opSdjT/3gcQoj4vT9lraE/Wzw7fJA94TNL5bavBTJf5cPzE84p6Zc8O0xRrqMgy QyzlWCzrSiVLql4OXFEjk/Pl3pJAoudfWxMaU9ZbWAUhlD26SQMAX5g8fYn4Ywm5psTS 7HJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tCsUXnjg; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o22-20020aa7d3d6000000b0046b44b34d88si3877427edr.310.2022.11.29.05.46.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 05:46:07 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tCsUXnjg; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18F793854541 for ; Tue, 29 Nov 2022 13:46:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18F793854541 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669729560; bh=lMmTzEwUPSaDOnCtfmtbjL6xLJglpZOtvxSojGgtH+k=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=tCsUXnjgklFl//57MMLrECeDshF9bsGH/O7jn0aq8lwd3wYLcUcH7X69sxoNTQrZv qac8HOFDYLbIu4Bt+EPfsv9/5VfccoUmggQ59L9tugqh1haulx30WiusIfc4uhNz25 Fj6SV2Bpal6mPFM9Ip2Zaa57H440enIEvSpkWr3k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 988813858C20; Tue, 29 Nov 2022 13:45:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 988813858C20 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2ATD6ghd033106; Tue, 29 Nov 2022 13:45:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m5hhyavb0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 13:45:14 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2ATCeWYQ027910; Tue, 29 Nov 2022 13:45:14 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m5hhyava7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 13:45:14 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2ATD5E9d007587; Tue, 29 Nov 2022 13:45:12 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma05fra.de.ibm.com with ESMTP id 3m3ae9b06a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 13:45:12 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2ATDjq6d12714594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Nov 2022 13:45:52 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F127A42041; Tue, 29 Nov 2022 13:45:09 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F36124203F; Tue, 29 Nov 2022 13:45:08 +0000 (GMT) Received: from pike.rch.stglabs.ibm.com (unknown [9.5.12.127]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 29 Nov 2022 13:45:08 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, guojiufu@linux.ibm.com, rguenther@suse.de, jeffreyalaw@gmail.com Subject: [PATCH 2/3] Use sub mode to move block for struct returns Date: Tue, 29 Nov 2022 21:45:06 +0800 Message-Id: <20221129134507.185951-2-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221129134507.185951-1-guojiufu@linux.ibm.com> References: <20221129134507.185951-1-guojiufu@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: R4u0Ixng6a161o7BSvQ3K88YCpwlF7cs X-Proofpoint-GUID: LozNvZqKvx7C9cNZikvOedYbsk3qd31K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-29_08,2022-11-29_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211290078 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo 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?1750838351705412677?= X-GMAIL-MSGID: =?utf-8?q?1750838351705412677?= Hi, This patch checks an assignment to see if it is copy block to a return variable, and if the function return through registers, then use the register mode to move sub-blocks for the assignment. Bootstraped and regtested on ppc{,le} and x86_64. Is this ok for trunk? BR, Jeff (Jiufu) PR target/65421 gcc/ChangeLog: * cfgexpand.cc (expand_used_vars): Mark DECL_USEDBY_RETURN_P for return vars. * expr.cc (expand_assignment): Call move_sub_blocks for assining to a struct return variable. * tree-core.h (struct tree_decl_common): Comment DECL_USEDBY_RETURN_P. * tree.h (DECL_USEDBY_RETURN_P): New define. --- gcc/cfgexpand.cc | 14 ++++++++++++++ gcc/expr.cc | 13 +++++++++++++ gcc/tree-core.h | 3 ++- gcc/tree.h | 4 ++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index dd29ffffc03..0783cb27a59 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -2158,6 +2158,20 @@ expand_used_vars (bitmap forced_stack_vars) frame_phase = off ? align - off : 0; } + /* Mark VARs on returns. */ + if (DECL_RESULT (current_function_decl)) + { + edge_iterator ei; + edge e; + FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) + if (greturn *ret = safe_dyn_cast (last_stmt (e->src))) + { + tree val = gimple_return_retval (ret); + if (val && VAR_P (val)) + DECL_USEDBY_RETURN_P (val) = 1; + } + } + /* Set TREE_USED on all variables in the local_decls. */ FOR_EACH_LOCAL_DECL (cfun, i, var) TREE_USED (var) = 1; diff --git a/gcc/expr.cc b/gcc/expr.cc index 201fee6fd9a..9be75d6733f 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -6115,6 +6115,19 @@ expand_assignment (tree to, tree from, bool nontemporal) return; } + /* If it is assigning to a struct var which will be returned, and the + function is returning via registers, it would be better to use the + register's mode to move sub-blocks for the assignment. */ + if (VAR_P (to) && DECL_USEDBY_RETURN_P (to) && mode == BLKmode + && TREE_CODE (from) != CONSTRUCTOR + && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == PARALLEL) + { + rtx ret = DECL_RTL (DECL_RESULT (current_function_decl)); + machine_mode sub_mode = GET_MODE (XEXP (XVECEXP (ret, 0, 0), 0)); + move_sub_blocks (to_rtx, from, sub_mode, nontemporal); + return; + } + /* Compute FROM and store the value in the rtx we got. */ push_temp_slots (); diff --git a/gcc/tree-core.h b/gcc/tree-core.h index e146b133dbd..de4acca9ba8 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1808,7 +1808,8 @@ struct GTY(()) tree_decl_common { In VAR_DECL, PARM_DECL and RESULT_DECL, this is DECL_HAS_VALUE_EXPR_P. */ unsigned decl_flag_2 : 1; - /* In FIELD_DECL, this is DECL_PADDING_P. */ + /* In FIELD_DECL, this is DECL_PADDING_P + In VAR_DECL, this is DECL_USEDBY_RETURN_P. */ unsigned decl_flag_3 : 1; /* Logically, these two would go in a theoretical base shared by var and parm decl. */ diff --git a/gcc/tree.h b/gcc/tree.h index 4a19de1c94d..b4fbf226ffc 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3007,6 +3007,10 @@ extern void decl_value_expr_insert (tree, tree); #define DECL_PADDING_P(NODE) \ (FIELD_DECL_CHECK (NODE)->decl_common.decl_flag_3) +/* Used in a VAR_DECL to indicate that it is used by a return stmt. */ +#define DECL_USEDBY_RETURN_P(NODE) \ + (VAR_DECL_CHECK (NODE)->decl_common.decl_flag_3) + /* Used in a FIELD_DECL to indicate whether this field is not a flexible array member. This is only valid for the last array type field of a structure. */