From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by sourceware.org (Postfix) with ESMTPS id 214393858D28 for ; Sun, 18 Jun 2023 13:03:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 214393858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=xen0n.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xen0n.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1687093414; bh=7i8Yk3Dy+Qesfl2Eyt3tU67oacO73RIFFIs366+lJVI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=nJgPs2T1cY8S5LzK+1pdV6HwNH+09lSL31ewEtI9/yvWMd/otiILc0KsYCVxqtU8L wIgJpvDzt5tN0KvWQ/iWQPrTMNpzYboeO1GNmYhQjrfKEy3QLUvWMilfGVJ9rchBt3 C94fMsdnH8dQs1fFhBq/i03BQ2j5yGu20BId8gbE= Received: from [192.168.9.172] (unknown [101.88.25.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 5E9A7600F8; Sun, 18 Jun 2023 21:03:34 +0800 (CST) Message-ID: Date: Sun, 18 Jun 2023 21:03:33 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [pushed][PATCH v3] LoongArch: Avoid non-returning indirect jumps through $ra [PR110136] To: Xi Ruoyao Cc: xuchenghua@loongson.cn, Andrew Pinski , Lulu Cheng , gcc-patches@gcc.gnu.org References: <20230615013033.505823-1-chenglulu@loongson.cn> Content-Language: en-US From: WANG Xuerui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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: Hi, On 6/15/23 17:03, Xi Ruoyao wrote: > Xuerui: I guess this makes it sensible to show "ret" instead of "jirl > $zero, $ra, 0" in objdump -d output, but I don't know how to implement > it. Do you have some idea? Thanks for the suggestion! Actually I have previously made this patch series [1] which included just that. But the Loongson maintainers said they're working on linker relaxation at that time so they would have to postpone processing it, and I've never had a review since then; it's expected to conflict with the relaxation patches so some rebasing would be needed, but IIRC all review comments should be addressed. You can take the series if you'd like to ;-) [1]: https://sourceware.org/pipermail/binutils/2023-February/126088.html > > On Thu, 2023-06-15 at 16:27 +0800, Lulu Cheng wrote: >> 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"