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)
}
[(set_attr "type" "branch")])
}
[(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"))]
""
(define_expand "indirect_jump"
[(set (pc) (match_operand 0 "register_operand"))]
""
})
(define_insn "@indirect_jump<mode>"
})
(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")
""
"jr\t%0"
[(set_attr "type" "jump")
(define_insn "@tablejump<mode>"
[(set (pc)
(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"
(use (label_ref (match_operand 1 "" "")))]
""
"jr\t%0"