From patchwork Tue Nov 29 13:45:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 27243 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp344446wrr; Tue, 29 Nov 2022 05:46:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf46Vlooqw1KPoly0OnrONWoZ+yG6rz97hGeNri85/AzrAVTXhiKWY2ReNtDKHVcL4uGZ/QY X-Received: by 2002:a17:906:1cf:b0:7bb:f0eb:a350 with SMTP id 15-20020a17090601cf00b007bbf0eba350mr19955363ejj.575.1669729564693; Tue, 29 Nov 2022 05:46:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669729564; cv=none; d=google.com; s=arc-20160816; b=O8InOXuaWyVQyZDtKS7ErLXUf8fcGLjfOdI5XtTDChJC79RENlJJFsPi8EyJvLq0F7 fpTAjQ/LU9DYlpvCYQVKfuQcSUXj250AJTo6mn6k6ex/hLZ+K+nfvCCqbp/5PQDT6a4x Vn7Xv4zAEB2xjlDbxs/sQ+dB0/D6L6Q1653gyhgCORE1B2ZcFqe+tAAPvvnABBRgzUvY CcEyAT7Bsu4bnnk0E9nH8kCx3Cik6ngt/nvS04Jj+KMCPy6WXSnhDorz8QpMg2Lt4o60 dM8y91hJotS+RylZnZdS9jQ0mVZIeX0zKJ7YpoEOENgV+3BKT/U9BECFv834QkHziGlu SffQ== 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:message-id:date :subject:cc:to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=gAJ5q6UawHSLI1gniVAc/xtWXalGRz5jJeBHOtBrm8o=; b=efP73/1q8cdymSI+2/aEKBjCOZrZwQR3YiOHm/7VppqLaBqysIX/Mm8z3Ed7Fm/lSC KqN9N+9JGFVl0Dseo3olLnBg55+K5Wa8SEZtVg6R23OMruZD4fIEwUddPRGLQj2pZIOn 2/wyxPAaDimGnnTVaF2PmyzsKZ3tyomoWErTm/CcMUbIzFrwyBTMZ1IUBSMzUX1gEbQJ g6ByPod0qZpFADu04CiNrgJb2BgBWsp8coHEG17jH561hKRshVspV7B4OrSuIBHdiPze XkrO1YTfXvq9LrQIckdbyWZ5yQn5ey+L3Zg+yvOPSdWCfeBwD16T4pMC8xDS9wHBYkox pl3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="j2zNCFL/"; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t13-20020a170906178d00b0078356aaeb63si8778953eje.288.2022.11.29.05.46.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 05:46:04 -0800 (PST) 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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="j2zNCFL/"; 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"; 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 E31C8385454B for ; Tue, 29 Nov 2022 13:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E31C8385454B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669729557; bh=gAJ5q6UawHSLI1gniVAc/xtWXalGRz5jJeBHOtBrm8o=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=j2zNCFL/pxyeAuLBwnoOrPneNP+V8dwijskJpzKrofpr3xpnEjJkwnLnG0iRZhYf6 r6PHddtr0hP5I+n2g3bafk+rvPqJF6UOsDrf7lhCi4zgaWVqUTp+OnS7C864LPmW4m F/KqtsheEKqLsdYWDc4VJoAsv2bdQba0lOKztoHQ= 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 E1B353858C53; Tue, 29 Nov 2022 13:45:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1B353858C53 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 2ATDfFn3033239; Tue, 29 Nov 2022 13:45:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m5hhyavaf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 13:45:13 +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 2ATCMJSW005237; Tue, 29 Nov 2022 13:45:13 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 3m5hhyav9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 13:45:13 +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 2ATD5E9c007587; Tue, 29 Nov 2022 13:45:11 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma05fra.de.ibm.com with ESMTP id 3m3ae9b068-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Nov 2022 13:45:11 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2ATDj87439452994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Nov 2022 13:45:08 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF15742041; Tue, 29 Nov 2022 13:45:08 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C22224203F; Tue, 29 Nov 2022 13:45:07 +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:07 +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 1/3] Use sub mode to move block for struct parameter Date: Tue, 29 Nov 2022 21:45:05 +0800 Message-Id: <20221129134507.185951-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: seFOdMLKfjmmz4SvXWEobLcc2a3U3SNu X-Proofpoint-GUID: n5z5_M92qngYu86kTpSGlQYIJALOTcrX 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?1750838348298954217?= X-GMAIL-MSGID: =?utf-8?q?1750838348298954217?= Hi, This patch checks an assignment to see if the "from" is about parameter, and if the parameter may passing 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) gcc/ChangeLog: * expr.cc (move_sub_blocks): New function. (expand_assignment): Call move_sub_blocks for assigning from parameter. --- gcc/expr.cc | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/gcc/expr.cc b/gcc/expr.cc index d9407432ea5..201fee6fd9a 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -5559,6 +5559,57 @@ mem_ref_refers_to_non_mem_p (tree ref) return non_mem_decl_p (base); } +/* Sub routine of expand_assignment, invoked when assigning from a + parameter or assigning to a return val on struct type which may + be passed through registers. The mode of register is used to + move the content for the assignment. + + This routine generates code for expression FROM which is BLKmode, + and move the generated content to TO_RTX by su-blocks in SUB_MODE. */ + +static void +move_sub_blocks (rtx to_rtx, tree from, machine_mode sub_mode, bool nontemporal) +{ + HOST_WIDE_INT size, sub_size; + int len; + + gcc_assert (MEM_P (to_rtx)); + + size = MEM_SIZE (to_rtx).to_constant (); + sub_size = GET_MODE_SIZE (sub_mode).to_constant (); + len = size / sub_size; + + /* As there are limit registers for passing parameters or return + value according target ABI. It would be not profitable to move + through sub-modes, if the size does not follow registers. */ + int heurisitic_num = 8; + if (!size || (size % sub_size) != 0 || len < 2 || len > heurisitic_num) + { + push_temp_slots (); + rtx result = store_expr (from, to_rtx, 0, nontemporal, false); + preserve_temp_slots (result); + pop_temp_slots (); + return; + } + + push_temp_slots (); + + rtx from_rtx; + from_rtx = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL); + for (int i = 0; i < len; i++) + { + rtx temp = gen_reg_rtx (sub_mode); + rtx src = adjust_address (from_rtx, sub_mode, sub_size * i); + rtx dest = adjust_address (to_rtx, sub_mode, sub_size * i); + emit_move_insn (temp, src); + emit_move_insn (dest, temp); + } + + preserve_temp_slots (to_rtx); + pop_temp_slots (); + return; +} + /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL is true, try generating a nontemporal store. */ @@ -6045,6 +6096,25 @@ expand_assignment (tree to, tree from, bool nontemporal) return; } + /* If it is assigning from a struct param which may be passed via registers, + It would be better to use the register's mode to move sub-blocks for the + assignment. */ + if (TREE_CODE (from) == PARM_DECL && mode == BLKmode + && DECL_INCOMING_RTL (from) + && (GET_CODE (DECL_INCOMING_RTL (from)) == PARALLEL + || REG_P (DECL_INCOMING_RTL (from)))) + { + rtx parm = DECL_INCOMING_RTL (from); + machine_mode sub_mode; + if (REG_P (parm)) + sub_mode = word_mode; + else + sub_mode = GET_MODE (XEXP (XVECEXP (parm, 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 ();