From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 77AA03858C1F for ; Thu, 15 Jun 2023 08:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77AA03858C1F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q9iKb-0007sq-3S for gcc-patches@gcc.gnu.org; Thu, 15 Jun 2023 04:27:52 -0400 Received: from loongson.cn (unknown [10.20.4.52]) by gateway (Coremail) with SMTP id _____8DxzOp_y4pkw3wFAA--.11739S3; Thu, 15 Jun 2023 16:27:43 +0800 (CST) Received: from [10.20.4.52] (unknown [10.20.4.52]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Ax6OR+y4pkELwbAA--.13294S2; Thu, 15 Jun 2023 16:27:43 +0800 (CST) Subject: Re: [pushed][PATCH v3] LoongArch: Avoid non-returning indirect jumps through $ra [PR110136] To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, Andrew Pinski References: <20230615013033.505823-1-chenglulu@loongson.cn> From: Lulu Cheng Message-ID: Date: Thu, 15 Jun 2023 16:27:42 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20230615013033.505823-1-chenglulu@loongson.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8Ax6OR+y4pkELwbAA--.13294S2 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW7Aw1rCw15ZrW8Zr4xuF4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received-SPF: pass client-ip=114.242.206.163; envelope-from=chenglulu@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9,MIME_CHARSET_FARAWAY=2.45,NICE_REPLY_A=-0.098,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,MIME_CHARSET_FARAWAY,NICE_REPLY_A,SPF_FAIL,SPF_HELO_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: Pushed to trunk and gcc-12 gcc-13. r14-1866 r13-7448 r12-9698 ÔÚ 2023/6/15 ÉÏÎç9:30, Lulu Cheng дµÀ: > Micro-architecture unconditionally treats a "jr $ra" as "return from subroutine", > hence doing "jr $ra" would interfere with both subroutine return prediction and > the more general indirect branch prediction. > > Therefore, a problem like PR110136 can cause a significant increase in branch error > prediction rate and affect performance. The same problem exists with "indirect_jump". > > gcc/ChangeLog: > > * config/loongarch/loongarch.md: Modify the register constraints for template > "jumptable" and "indirect_jump" from "r" to "e". > > Co-authored-by: Andrew Pinski > --- > v1 -> v2: > 1. Modify the description. > 2. Modify the register constraints of the template "indirect_jump". > v2 -> v3: > 1. Modify the description. > --- > gcc/config/loongarch/loongarch.md | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md > index 816a943d155..b37e070660f 100644 > --- a/gcc/config/loongarch/loongarch.md > +++ b/gcc/config/loongarch/loongarch.md > @@ -2895,6 +2895,10 @@ (define_insn "*jump_pic" > } > [(set_attr "type" "branch")]) > > +;; Micro-architecture unconditionally treats a "jr $ra" as "return from subroutine", > +;; non-returning indirect jumps through $ra would interfere with both subroutine > +;; return prediction and the more general indirect branch prediction. > + > (define_expand "indirect_jump" > [(set (pc) (match_operand 0 "register_operand"))] > "" > @@ -2905,7 +2909,7 @@ (define_expand "indirect_jump" > }) > > (define_insn "@indirect_jump" > - [(set (pc) (match_operand:P 0 "register_operand" "r"))] > + [(set (pc) (match_operand:P 0 "register_operand" "e"))] > "" > "jr\t%0" > [(set_attr "type" "jump") > @@ -2928,7 +2932,7 @@ (define_expand "tablejump" > > (define_insn "@tablejump" > [(set (pc) > - (match_operand:P 0 "register_operand" "r")) > + (match_operand:P 0 "register_operand" "e")) > (use (label_ref (match_operand 1 "" "")))] > "" > "jr\t%0"