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>
This commit is contained in:
Lulu Cheng 2023-06-07 10:21:58 +08:00
parent b992bddac7
commit 5430c86e71

View file

@ -2895,6 +2895,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"))]
""
@ -2905,7 +2909,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")
@ -2928,7 +2932,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"