aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLulu Cheng <chenglulu@loongson.cn>2023-06-07 10:21:58 +0800
committerLulu Cheng <chenglulu@loongson.cn>2023-06-15 16:23:42 +0800
commitddec24e5abe99033c8d6bbe544b4c2b35a0232f2 (patch)
tree1048417dd3564c222b029531f010d1f094e6928a
parenta58bda46377ba74df9ba2bf0a22111c74a1abae8 (diff)
downloadgcc-ddec24e5abe99033c8d6bbe544b4c2b35a0232f2.zip
gcc-ddec24e5abe99033c8d6bbe544b4c2b35a0232f2.tar.gz
gcc-ddec24e5abe99033c8d6bbe544b4c2b35a0232f2.tar.bz2
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)
-rw-r--r--gcc/config/loongarch/loongarch.md8
1 files changed, 6 insertions, 2 deletions
diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index 8f8412f..a64142c 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -2622,6 +2622,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"))]
""
@@ -2632,7 +2636,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")
@@ -2655,7 +2659,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"