public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Lulu Cheng <chenglulu@loongson.cn>
To: gcc-patches@gcc.gnu.org
Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn,
	Andrew Pinski <apinski@marvell.com>
Subject: Re: [pushed][PATCH v3] LoongArch: Avoid non-returning indirect jumps through $ra [PR110136]
Date: Thu, 15 Jun 2023 16:27:42 +0800	[thread overview]
Message-ID: <e77a70a1-5ea9-a676-2b79-ae4c9e739a5c@loongson.cn> (raw)
In-Reply-To: <20230615013033.505823-1-chenglulu@loongson.cn>

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 <apinski@marvell.com>
> ---
> 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<mode>"
> -  [(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<mode>"
>     [(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"


  reply	other threads:[~2023-06-15  8:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15  1:30 [PATCH " Lulu Cheng
2023-06-15  8:27 ` Lulu Cheng [this message]
2023-06-15  9:03   ` [pushed][PATCH " Xi Ruoyao
2023-06-18 13:03     ` WANG Xuerui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e77a70a1-5ea9-a676-2b79-ae4c9e739a5c@loongson.cn \
    --to=chenglulu@loongson.cn \
    --cc=apinski@marvell.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=i@xen0n.name \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).