[NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine
[llvm-project.git] / llvm / test / CodeGen / AArch64 / patchable-function-entry-bti.ll
blob0dfb5764f55b8cc0f70e2258612e546e81781c45
1 ; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
3 define void @f0() "patchable-function-entry"="0" "branch-target-enforcement"="true" {
4 ; CHECK-LABEL: f0:
5 ; CHECK-NEXT: .Lfunc_begin0:
6 ; CHECK:      // %bb.0:
7 ; CHECK-NEXT:  hint #34
8 ; CHECK-NEXT:  ret
9 ; CHECK-NOT:  .section __patchable_function_entries
10   ret void
13 ;; -fpatchable-function-entry=1 -mbranch-protection=bti
14 ;; For M=0, place the label .Lpatch0 after the initial BTI.
15 define void @f1() "patchable-function-entry"="1" "branch-target-enforcement"="true" {
16 ; CHECK-LABEL: f1:
17 ; CHECK-NEXT: .Lfunc_begin1:
18 ; CHECK-NEXT: .cfi_startproc
19 ; CHECK-NEXT: // %bb.0:
20 ; CHECK-NEXT:  hint #34
21 ; CHECK-NEXT: .Lpatch0:
22 ; CHECK-NEXT:  nop
23 ; CHECK-NEXT:  ret
24 ; CHECK:      .section __patchable_function_entries,"awo",@progbits,f1{{$}}
25 ; CHECK-NEXT: .p2align 3
26 ; CHECK-NEXT: .xword .Lpatch0
27   ret void
30 ;; -fpatchable-function-entry=2,1 -mbranch-protection=bti
31 define void @f2_1() "patchable-function-entry"="1" "patchable-function-prefix"="1" "branch-target-enforcement"="true" {
32 ; CHECK-LABEL: .type f2_1,@function
33 ; CHECK-NEXT: .Ltmp0:
34 ; CHECK-NEXT:  nop
35 ; CHECK-NEXT: f2_1:
36 ; CHECK-NEXT: .Lfunc_begin2:
37 ; CHECK-NEXT: .cfi_startproc
38 ; CHECK-NEXT: // %bb.0:
39 ; CHECK-NEXT:  hint #34
40 ; CHECK-NEXT:  nop
41 ; CHECK-NEXT:  ret
42 ; CHECK:      .Lfunc_end2:
43 ; CHECK-NEXT: .size f2_1, .Lfunc_end2-f2_1
44 ; CHECK:      .section __patchable_function_entries,"awo",@progbits,f2_1{{$}}
45 ; CHECK-NEXT: .p2align 3
46 ; CHECK-NEXT: .xword .Ltmp0
47   ret void
50 ;; -fpatchable-function-entry=1 -mbranch-protection=bti
51 ;; We add BTI c even when the function has internal linkage
52 define internal void @f1i(i64 %v) "patchable-function-entry"="1" "branch-target-enforcement"="true" {
53 ; CHECK-LABEL: f1i:
54 ; CHECK-NEXT: .Lfunc_begin3:
55 ; CHECK:      // %bb.0:
56 ; CHECK-NEXT:  hint #34
57 ; CHECK-NEXT:  .Lpatch1:
58 ; CHECK-NEXT:  nop
59 ;; Other basic blocks have BTI, but they don't affect our decision to not create .Lpatch0
60 ; CHECK:      .LBB{{.+}} // %sw.bb1
61 ; CHECK-NEXT:  hint #36
62 ; CHECK:      .section __patchable_function_entries,"awo",@progbits,f1i{{$}}
63 ; CHECK-NEXT: .p2align 3
64 ; CHECK-NEXT: .xword .Lpatch1
65 entry:
66   switch i64 %v, label %sw.bb0 [
67     i64 1, label %sw.bb1
68     i64 2, label %sw.bb2
69     i64 3, label %sw.bb3
70     i64 4, label %sw.bb4
71   ]
72 sw.bb0:
73   call void asm sideeffect "", ""()
74   ret void
75 sw.bb1:
76   call void asm sideeffect "", ""()
77   ret void
78 sw.bb2:
79   call void asm sideeffect "", ""()
80   ret void
81 sw.bb3:
82   call void asm sideeffect "", ""()
83   ret void
84 sw.bb4:
85   call void asm sideeffect "", ""()
86   ret void
89 ;; Test the interaction with -fsanitize=function.
90 ; CHECK:      .type sanitize_function,@function
91 ; CHECK-NEXT: .Ltmp{{.*}}:
92 ; CHECK-NEXT:   nop
93 ; CHECK-NEXT:   .word   3238382334  // 0xc105cafe
94 ; CHECK-NEXT:   .word   42
95 ; CHECK-NEXT: sanitize_function:
96 ; CHECK-NEXT: .Lfunc_begin{{.*}}:
97 ; CHECK-NEXT:   .cfi_startproc
98 ; CHECK-NEXT:   // %bb.0:
99 ; CHECK-NEXT:   hint #34
100 ; CHECK-NEXT:   nop
101 ; CHECK-NEXT:   ret
102 define void @sanitize_function(ptr noundef %x) "patchable-function-prefix"="1" "patchable-function-entry"="1" "branch-target-enforcement"="true" !func_sanitize !0 {
103   ret void
106 !0 = !{i32 3238382334, i32 42}