From patchwork Thu Aug 1 10:12:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Surya Kumari Jangala X-Patchwork-Id: 1967585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=IYnUcJIC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZPtm3TKbz1ybV for ; Thu, 1 Aug 2024 20:13:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8203E385DDC8 for ; Thu, 1 Aug 2024 10:13:34 +0000 (GMT) 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 DB9A13858C33 for ; Thu, 1 Aug 2024 10:12:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB9A13858C33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB9A13858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722507182; cv=none; b=YfcY/o39cRhA53M/vnbXzsIUEL7EQwm1wz2g5Sqq/cLVePNwOBAr57bV8qZ5FXH7+0yTeWvq4XAzcU0B74lYUyGe0Xqv9v2jp6lgrVkOwEYtroffg342EPiRORWBVm9eKc4UtJOhafL9FoanMstQG1fhFSnna14MHA9jqccdsMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722507182; c=relaxed/simple; bh=0N7IXtSySxECGMuz4LP/nHSlcaVUnrabdjiMujsm1kg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=stfOw7qnrPHwuhSIiUPEYMSN79RHmhkLfyZQqnXewN6R2hWjfdtFhlK8iipVQJkCyBFJMUmgAwzlzLNL/gB3UrjoQSZm31ZdvqVDa5ikXu6WEFmIMTDu1pMtB4onGcp8y3SFnXfPzYZ94mRckC6xtQUPHumpGCAv8OcO20nZFqs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4713Q6Th005686; Thu, 1 Aug 2024 10:12:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:mime-version:to:from:cc:subject:content-type :content-transfer-encoding; s=pp1; bh=z0YjMhhaAu0FBouBLtmtxOOEAA Z9/fKHukoZCgJzQ+k=; b=IYnUcJICMoz4FWO6OkG79cWqoQYEaa2e27F5XdWqPq krg1/GsBXeaejAF3hPJtQCOCR3ZJuygDV5HuTs1M6Gn74TApjGZ9khriBcsFG9sf vcnUHGZIQz0F4j+SdFSG3L1HOHlX55SbTaRU6AdgVoXxZPh5QFT2NZFCfywmSJyo J2jgkC0e7x0b4as+mGlx53GkYOUDnG/7GLg6cL3XnS5v7kXS04M7enp1QjCJ/WnC kQdTMUmn1p55ZjXaVXy7pBc5roPc6DHkhGZ1CUhzzvYp6wZYjZ5ABZgnZCVeI+yJ 9hviK54X8Dc77uqirWwwkOmNbTG+UZTIsSbpUW8fBWCQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40qyup965e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Aug 2024 10:12:55 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 471ABT2X008377; Thu, 1 Aug 2024 10:12:55 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40qyup965b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Aug 2024 10:12:54 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4717wUqq029118; Thu, 1 Aug 2024 10:12:54 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 40nbm119kr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Aug 2024 10:12:54 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 471ACpYu25494236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Aug 2024 10:12:54 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 99E7E5805D; Thu, 1 Aug 2024 10:12:51 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2BF9F58067; Thu, 1 Aug 2024 10:12:50 +0000 (GMT) Received: from [9.109.195.192] (unknown [9.109.195.192]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 1 Aug 2024 10:12:49 +0000 (GMT) Message-ID: <9e7c4797-a930-45fe-9ac1-91d750645407@linux.ibm.com> Date: Thu, 1 Aug 2024 15:42:48 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Vladimir Makarov , Richard Sandiford , GCC Patches From: Surya Kumari Jangala Cc: Peter Bergner Subject: [PATCH] lra: emit caller-save register spills before call insn [PR116028] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rQWAUs4JfQk16i-tJkdd51G6baz44Fw8 X-Proofpoint-ORIG-GUID: 0v5bwwLwp7sB4-Hf96bz9uwc47giH2UX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-01_07,2024-07-31_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxlogscore=683 mlxscore=0 clxscore=1011 bulkscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408010061 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org lra: emit caller-save register spills before call insn [PR116028] LRA emits insns to save caller-save registers in the inheritance/splitting pass. In this pass, LRA builds EBBs (Extended Basic Block) and traverses the insns in the EBBs in reverse order from the last insn to the first insn. When LRA sees a write to a pseudo (that has been assigned a caller-save register), and there is a read following the write, with an intervening call insn between the write and read, then LRA generates a spill immediately after the write and a restore immediately before the read. The spill is needed because the call insn will clobber the caller-save register. If there is a write insn and a call insn in two separate BBs but belonging to the same EBB, the spill insn gets generated in the BB containing the write insn. If the write insn is in the entry BB, then the spill insn that is generated in the entry BB prevents shrink wrap from happening. This is because the spill insn references the stack pointer and hence the prolog gets generated in the entry BB itself. This patch ensures that the spill insn is generated before the call insn instead of after the write. This is also more efficient as the spill now occurs only in the path containing the call. 2024-08-01 Surya Kumari Jangala gcc/ PR rtl-optimization/PR116028 * lra-constraints.cc (split_reg): Spill register before call insn. (latest_call_insn): New variable. (inherit_in_ebb): Track the latest call insn. gcc/testsuite/ PR rtl-optimization/PR116028 * gcc.dg/ira-shrinkwrap-prep-1.c: Remove xfail for powerpc. * gcc.dg/pr10474.c: Remove xfail for powerpc. diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 92b343fa99a..34f2461f791 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -143,6 +143,7 @@ static int bb_reload_num; (NULL otherwise), its data (basic block, the insn data, the insn static data, and the mode of each operand). */ static rtx_insn *curr_insn; +static rtx_insn *latest_call_insn; static rtx curr_insn_set; static basic_block curr_bb; static lra_insn_recog_data_t curr_id; @@ -6286,10 +6287,14 @@ split_reg (bool before_p, int original_regno, rtx_insn *insn, after_p ? restore : NULL, call_save_p ? "Add reg<-save" : "Add reg<-split"); - lra_process_new_insns (insn, before_p ? save : NULL, - before_p ? NULL : save, - call_save_p - ? "Add save<-reg" : "Add split<-reg"); + if (call_save_p) + lra_process_new_insns (PREV_INSN (latest_call_insn), NULL, save, + "Add save<-reg"); + else + lra_process_new_insns (insn, before_p ? save : NULL, + before_p ? NULL : save, + call_save_p + ? "Add save<-reg" : "Add split<-reg"); if (nregs > 1 || original_regno < FIRST_PSEUDO_REGISTER) /* If we are trying to split multi-register. We should check conflicts on the next assignment sub-pass. IRA can allocate on @@ -6773,6 +6778,7 @@ inherit_in_ebb (rtx_insn *head, rtx_insn *tail) last_processed_bb = NULL; CLEAR_HARD_REG_SET (potential_reload_hard_regs); live_hard_regs = eliminable_regset | lra_no_alloc_regs; + latest_call_insn = NULL; /* We don't process new insns generated in the loop. */ for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn) { @@ -6985,6 +6991,7 @@ inherit_in_ebb (rtx_insn *head, rtx_insn *tail) last_call_for_abi[callee_abi.id ()] = calls_num; full_and_partial_call_clobbers |= callee_abi.full_and_partial_reg_clobbers (); + latest_call_insn = curr_insn; if ((cheap = find_reg_note (curr_insn, REG_RETURNED, NULL_RTX)) != NULL_RTX && ((cheap = XEXP (cheap, 0)), true) diff --git a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c index a95637abbe5..8c150972f95 100644 --- a/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c +++ b/gcc/testsuite/gcc.dg/ira-shrinkwrap-prep-1.c @@ -26,4 +26,4 @@ bar (long a) /* { dg-final { scan-rtl-dump "Will split live ranges of parameters" "ira" } } */ /* { dg-final { scan-rtl-dump "Split live-range of register" "ira" { xfail { ! aarch64*-*-* } } } } */ -/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" { xfail powerpc*-*-* } } } */ +/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" } } */ diff --git a/gcc/testsuite/gcc.dg/pr10474.c b/gcc/testsuite/gcc.dg/pr10474.c index a4af536ec28..b5393d5b6e3 100644 --- a/gcc/testsuite/gcc.dg/pr10474.c +++ b/gcc/testsuite/gcc.dg/pr10474.c @@ -13,4 +13,4 @@ void f(int *i) } /* XFAIL due to PR70681. */ -/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" { xfail arm*-*-* powerpc*-*-* } } } */ +/* { dg-final { scan-rtl-dump "Performing shrink-wrapping" "pro_and_epilogue" { xfail arm*-*-* } } } */