public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7448] LoongArch: Avoid non-returning indirect jumps through $ra [PR110136]
@ 2023-06-15  8:26 LuluCheng
  0 siblings, 0 replies; only message in thread
From: LuluCheng @ 2023-06-15  8:26 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f829733b5c92877247727347246d9f927372f0c1

commit r13-7448-gf829733b5c92877247727347246d9f927372f0c1
Author: Lulu Cheng <chenglulu@loongson.cn>
Date:   Wed Jun 7 10:21:58 2023 +0800

    LoongArch: Avoid non-returning indirect jumps through $ra [PR110136]
    
    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:
    
            PR target/110136
            * 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>
    
    (cherry picked from commit 5430c86e71927492399129f3df80824c6c334ddf)

Diff:
---
 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 3509c3c21c1..43c3578b6db 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2854,6 +2854,10 @@
 }
   [(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"))]
   ""
@@ -2864,7 +2868,7 @@
 })
 
 (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")
@@ -2887,7 +2891,7 @@
 
 (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"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-15  8:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15  8:26 [gcc r13-7448] LoongArch: Avoid non-returning indirect jumps through $ra [PR110136] LuluCheng

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).