return false;
}
+/* Check if INSN is a BTI J insn. */
+static bool
+aarch64_bti_j_insn_p (rtx_insn *insn)
+{
+ if (!insn || !INSN_P (insn))
+ return false;
+
+ rtx pat = PATTERN (insn);
+ return GET_CODE (pat) == UNSPEC_VOLATILE && XINT (pat, 1) == UNSPECV_BTI_J;
+}
+
/* Insert the BTI instruction. */
/* This is implemented as a late RTL pass that runs before branch
shortening and does the following. */
for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
{
label = as_a <rtx_insn *> (XEXP (RTVEC_ELT (vec, j), 0));
+ rtx_insn *next = next_nonnote_nondebug_insn (label);
+ if (aarch64_bti_j_insn_p (next))
+ continue;
+
bti_insn = gen_bti_j ();
emit_insn_after (bti_insn, label);
}
--- /dev/null
+/* { dg-do compile { target lp64 } } */
+/* { dg-options "-O2 -mbranch-protection=standard" } */
+/* { dg-final { scan-assembler-times {bti j} 13 } } */
+int a;
+int c();
+int d();
+int e();
+int f();
+int g();
+void h() {
+ switch (a) {
+ case 0:
+ case 56:
+ case 57:
+ break;
+ case 58:
+ case 59:
+ case 61:
+ case 62:
+ c();
+ case 64:
+ case 63:
+ d();
+ case 66:
+ case 65:
+ d();
+ case 68:
+ case 67:
+ d();
+ case 69:
+ case 70:
+ d();
+ case 71:
+ case 72:
+ case 88:
+ case 87:
+ d();
+ case 90:
+ case 89:
+ d();
+ case 92:
+ case 1:
+ d();
+ case 93:
+ case 73:
+ case 4:
+ e();
+ case 76:
+ case 5:
+ f();
+ case 7:
+ case 8:
+ case 84:
+ case 85:
+ break;
+ case 6:
+ case 299:
+ case 9:
+ case 80:
+ case 2:
+ case 3:
+ e();
+ default:
+ g();
+ }
+}