From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 827B63858D1E for ; Sat, 22 Jul 2023 16:44:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 827B63858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=v/OQyURpyIzAFDQ9AGpSVvOz/4DqvjLgLfXtwAc4evI=; b=DQcXdIpulERQs6eEdIQ3AcQfEF l0avCipr34uCAOQ8i9uTK3EO0DH//iFZWF6mmA0zERtmayM6URmowJM6Y8dERx2Gd7q4TSk5jW0IG t7oJhudSJhB8Uv8qAvB0owsd2/xiMXOZP7idyxqBRffKDIJc8pS2SwBIHlhzIDIGGmJa9pnUflNkI I6FphM+mmpiyrWnW5p82LVa62e5Iz45WU/KajekwSy5ak6+wXWplxR5aZUsiwKw7efoEDzGeEizTJ YsjG4kRNYqzu8G2TBQ41Ye2XzP0g2IV4Sh27ArtTzPw413JveXR55JRz8SPgFKtTo+GPR9bIvgXOf Wie8TDtA==; Received: from [185.62.158.67] (port=60547 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qNFis-0006Hf-1Y for gcc-patches@gcc.gnu.org; Sat, 22 Jul 2023 12:44:50 -0400 From: "Roger Sayle" To: Subject: [PATCH] Replace lra-spill.cc's return_regno_p with return_reg_p. Date: Sat, 22 Jul 2023 17:44:48 +0100 Message-ID: <00ef01d9bcbb$d50aeeb0$7f20cc10$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00F0_01D9BCC4.36D1C7B0" X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adm8uxDJJni4UI3FT8qk52NICcHomw== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is a multipart message in MIME format. ------=_NextPart_000_00F0_01D9BCC4.36D1C7B0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch is my attempt to address the compile-time hog issue in PR rtl-optimization/110587. Richard Biener's analysis shows that compilation of pr28071.c with -O0 currently spends ~70% in timer "LRA non-specific" due to return_regno_p failing to filter a large number of calls to regno_in_use_p, resulting in quadratic behaviour. For this pathological test case, things can be improved significantly. Although the return register (%rax) is indeed mentioned a large number of times in this function, due to inlining, the inlined functions access the returned register in TImode, whereas the current function returns a DImode. Hence the check to see if we're the last SET of the return register, which should be followed by a USE, can be improved by also testing the mode. Implementation-wise, rather than pass an additional mode parameter to LRA's local return_regno_p function, which only has a single caller, it's more convenient to pass the rtx REG_P, and from this extract both the REGNO and the mode in the callee, and rename this function to return_reg_p. The good news is that with this change "LRA non-specific" drops from 70% to 13%. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, with no new failures. Ok for mainline? 2023-07-22 Roger Sayle gcc/ChangeLog PR middle-end/28071 PR rtl-optimization/110587 * lra-spills.cc (return_regno_p): Change argument and rename to... (return_reg_p): Check if the given register RTX has the same REGNO and machine mode as the function's return value. (lra_final_code_change): Update call to return_reg_p. Thanks in advance, Roger -- ------=_NextPart_000_00F0_01D9BCC4.36D1C7B0 Content-Type: text/plain; name="patchrr.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchrr.txt" diff --git a/gcc/lra-spills.cc b/gcc/lra-spills.cc=0A= index 3a7bb7e..ae147ad 100644=0A= --- a/gcc/lra-spills.cc=0A= +++ b/gcc/lra-spills.cc=0A= @@ -705,10 +705,10 @@ alter_subregs (rtx *loc, bool final_p)=0A= return res;=0A= }=0A= =0A= -/* Return true if REGNO is used for return in the current=0A= - function. */=0A= +/* Return true if register REG, known to be REG_P, is used for return=0A= + in the current function. */=0A= static bool=0A= -return_regno_p (unsigned int regno)=0A= +return_reg_p (rtx reg)=0A= {=0A= rtx outgoing =3D crtl->return_rtx;=0A= =0A= @@ -716,7 +716,8 @@ return_regno_p (unsigned int regno)=0A= return false;=0A= =0A= if (REG_P (outgoing))=0A= - return REGNO (outgoing) =3D=3D regno;=0A= + return REGNO (outgoing) =3D=3D REGNO (reg)=0A= + && GET_MODE (outgoing) =3D=3D GET_MODE (reg);=0A= else if (GET_CODE (outgoing) =3D=3D PARALLEL)=0A= {=0A= int i;=0A= @@ -725,7 +726,9 @@ return_regno_p (unsigned int regno)=0A= {=0A= rtx x =3D XEXP (XVECEXP (outgoing, 0, i), 0);=0A= =0A= - if (REG_P (x) && REGNO (x) =3D=3D regno)=0A= + if (REG_P (x)=0A= + && REGNO (x) =3D=3D REGNO (reg)=0A= + && GET_MODE (x) =3D=3D GET_MODE (reg))=0A= return true;=0A= }=0A= }=0A= @@ -821,7 +824,7 @@ lra_final_code_change (void)=0A= if (NONJUMP_INSN_P (insn) && GET_CODE (pat) =3D=3D SET=0A= && REG_P (SET_SRC (pat)) && REG_P (SET_DEST (pat))=0A= && REGNO (SET_SRC (pat)) =3D=3D REGNO (SET_DEST (pat))=0A= - && (! return_regno_p (REGNO (SET_SRC (pat)))=0A= + && (! return_reg_p (SET_SRC (pat))=0A= || ! regno_in_use_p (insn, REGNO (SET_SRC (pat)))))=0A= {=0A= lra_invalidate_insn_data (insn);=0A= ------=_NextPart_000_00F0_01D9BCC4.36D1C7B0--