[NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine
[llvm-project.git] / llvm / test / CodeGen / AArch64 / sign-return-address.ll
blob5680915c7f414c08b839412fc9714061c3349680
1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -mtriple=aarch64              < %s | FileCheck --check-prefixes=CHECK,COMPAT %s
3 ; RUN: llc -mtriple=aarch64 -mattr=v8.3a < %s | FileCheck --check-prefixes=CHECK,V83A %s
5 define i32 @leaf(i32 %x) {
6 ; CHECK-LABEL: leaf:
7 ; CHECK:       // %bb.0:
8 ; CHECK-NEXT:    ret
9   ret i32 %x
12 define i32 @leaf_sign_none(i32 %x) "sign-return-address"="none"  {
13 ; CHECK-LABEL: leaf_sign_none:
14 ; CHECK:       // %bb.0:
15 ; CHECK-NEXT:    ret
16   ret i32 %x
19 define i32 @leaf_sign_non_leaf(i32 %x) "sign-return-address"="non-leaf"  {
20 ; CHECK-LABEL: leaf_sign_non_leaf:
21 ; CHECK:       // %bb.0:
22 ; CHECK-NEXT:    ret
23   ret i32 %x
26 define i32 @leaf_sign_all(i32 %x) "sign-return-address"="all" {
27 ; COMPAT-LABEL: leaf_sign_all:
28 ; COMPAT:       // %bb.0:
29 ; COMPAT-NEXT:    hint #25
30 ; COMPAT-NEXT:    .cfi_negate_ra_state
31 ; COMPAT-NEXT:    hint #29
32 ; COMPAT-NEXT:    ret
34 ; V83A-LABEL: leaf_sign_all:
35 ; V83A:       // %bb.0:
36 ; V83A-NEXT:    paciasp
37 ; V83A-NEXT:    .cfi_negate_ra_state
38 ; V83A-NEXT:    retaa
39   ret i32 %x
42 define i64 @leaf_clobbers_lr(i64 %x) "sign-return-address"="non-leaf"  {
43 ; COMPAT-LABEL: leaf_clobbers_lr:
44 ; COMPAT:       // %bb.0:
45 ; COMPAT-NEXT:    hint #25
46 ; COMPAT-NEXT:    .cfi_negate_ra_state
47 ; COMPAT-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
48 ; COMPAT-NEXT:    .cfi_def_cfa_offset 16
49 ; COMPAT-NEXT:    .cfi_offset w30, -16
50 ; COMPAT-NEXT:    //APP
51 ; COMPAT-NEXT:    mov x30, x0
52 ; COMPAT-NEXT:    //NO_APP
53 ; COMPAT-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
54 ; COMPAT-NEXT:    hint #29
55 ; COMPAT-NEXT:    ret
57 ; V83A-LABEL: leaf_clobbers_lr:
58 ; V83A:       // %bb.0:
59 ; V83A-NEXT:    paciasp
60 ; V83A-NEXT:    .cfi_negate_ra_state
61 ; V83A-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
62 ; V83A-NEXT:    .cfi_def_cfa_offset 16
63 ; V83A-NEXT:    .cfi_offset w30, -16
64 ; V83A-NEXT:    //APP
65 ; V83A-NEXT:    mov x30, x0
66 ; V83A-NEXT:    //NO_APP
67 ; V83A-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
68 ; V83A-NEXT:    retaa
69   call void asm sideeffect "mov x30, $0", "r,~{lr}"(i64 %x) #1
70   ret i64 %x
73 declare i32 @foo(i32)
75 define i32 @non_leaf_sign_all(i32 %x) "sign-return-address"="all" {
76 ; COMPAT-LABEL: non_leaf_sign_all:
77 ; COMPAT:       // %bb.0:
78 ; COMPAT-NEXT:    hint #25
79 ; COMPAT-NEXT:    .cfi_negate_ra_state
80 ; COMPAT-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
81 ; COMPAT-NEXT:    .cfi_def_cfa_offset 16
82 ; COMPAT-NEXT:    .cfi_offset w30, -16
83 ; COMPAT-NEXT:    bl foo
84 ; COMPAT-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
85 ; COMPAT-NEXT:    hint #29
86 ; COMPAT-NEXT:    ret
88 ; V83A-LABEL: non_leaf_sign_all:
89 ; V83A:       // %bb.0:
90 ; V83A-NEXT:    paciasp
91 ; V83A-NEXT:    .cfi_negate_ra_state
92 ; V83A-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
93 ; V83A-NEXT:    .cfi_def_cfa_offset 16
94 ; V83A-NEXT:    .cfi_offset w30, -16
95 ; V83A-NEXT:    bl foo
96 ; V83A-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
97 ; V83A-NEXT:    retaa
98   %call = call i32 @foo(i32 %x)
99   ret i32 %call
102 define i32 @non_leaf_sign_non_leaf(i32 %x) "sign-return-address"="non-leaf"  {
103 ; COMPAT-LABEL: non_leaf_sign_non_leaf:
104 ; COMPAT:       // %bb.0:
105 ; COMPAT-NEXT:    hint #25
106 ; COMPAT-NEXT:    .cfi_negate_ra_state
107 ; COMPAT-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
108 ; COMPAT-NEXT:    .cfi_def_cfa_offset 16
109 ; COMPAT-NEXT:    .cfi_offset w30, -16
110 ; COMPAT-NEXT:    bl foo
111 ; COMPAT-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
112 ; COMPAT-NEXT:    hint #29
113 ; COMPAT-NEXT:    ret
115 ; V83A-LABEL: non_leaf_sign_non_leaf:
116 ; V83A:       // %bb.0:
117 ; V83A-NEXT:    paciasp
118 ; V83A-NEXT:    .cfi_negate_ra_state
119 ; V83A-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
120 ; V83A-NEXT:    .cfi_def_cfa_offset 16
121 ; V83A-NEXT:    .cfi_offset w30, -16
122 ; V83A-NEXT:    bl foo
123 ; V83A-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
124 ; V83A-NEXT:    retaa
125   %call = call i32 @foo(i32 %x)
126   ret i32 %call
129 ; Should not use the RETAA instruction.
130 define i32 @non_leaf_scs(i32 %x) "sign-return-address"="non-leaf" shadowcallstack "target-features"="+v8.3a,+reserve-x18"  {
131 ; CHECK-LABEL: non_leaf_scs:
132 ; CHECK:       // %bb.0:
133 ; CHECK-NEXT:    str x30, [x18], #8
134 ; CHECK-NEXT:    .cfi_escape 0x16, 0x12, 0x02, 0x82, 0x78 //
135 ; CHECK-NEXT:    paciasp
136 ; CHECK-NEXT:    .cfi_negate_ra_state
137 ; CHECK-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
138 ; CHECK-NEXT:    .cfi_def_cfa_offset 16
139 ; CHECK-NEXT:    .cfi_offset w30, -16
140 ; CHECK-NEXT:    bl foo
141 ; CHECK-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
142 ; CHECK-NEXT:    autiasp
143 ; CHECK-NEXT:    ldr x30, [x18, #-8]!
144 ; CHECK-NEXT:    ret
145   %call = call i32 @foo(i32 %x)
146   ret i32 %call
149 define i32 @leaf_sign_all_v83(i32 %x) "sign-return-address"="all" "target-features"="+v8.3a" {
150 ; CHECK-LABEL: leaf_sign_all_v83:
151 ; CHECK:       // %bb.0:
152 ; CHECK-NEXT:    paciasp
153 ; CHECK-NEXT:    .cfi_negate_ra_state
154 ; CHECK-NEXT:    retaa
155   ret i32 %x
158 declare fastcc i64 @bar(i64)
160 define fastcc void @spill_lr_and_tail_call(i64 %x) "sign-return-address"="all" {
161 ; COMPAT-LABEL: spill_lr_and_tail_call:
162 ; COMPAT:       // %bb.0:
163 ; COMPAT-NEXT:    hint #25
164 ; COMPAT-NEXT:    .cfi_negate_ra_state
165 ; COMPAT-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
166 ; COMPAT-NEXT:    .cfi_def_cfa_offset 16
167 ; COMPAT-NEXT:    .cfi_offset w30, -16
168 ; COMPAT-NEXT:    //APP
169 ; COMPAT-NEXT:    mov x30, x0
170 ; COMPAT-NEXT:    //NO_APP
171 ; COMPAT-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
172 ; COMPAT-NEXT:    hint #29
173 ; COMPAT-NEXT:    b bar
175 ; V83A-LABEL: spill_lr_and_tail_call:
176 ; V83A:       // %bb.0:
177 ; V83A-NEXT:    paciasp
178 ; V83A-NEXT:    .cfi_negate_ra_state
179 ; V83A-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
180 ; V83A-NEXT:    .cfi_def_cfa_offset 16
181 ; V83A-NEXT:    .cfi_offset w30, -16
182 ; V83A-NEXT:    //APP
183 ; V83A-NEXT:    mov x30, x0
184 ; V83A-NEXT:    //NO_APP
185 ; V83A-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
186 ; V83A-NEXT:    autiasp
187 ; V83A-NEXT:    b bar
188   call void asm sideeffect "mov x30, $0", "r,~{lr}"(i64 %x) #1
189   tail call fastcc i64 @bar(i64 %x)
190   ret void
193 define i32 @leaf_sign_all_a_key(i32 %x) "sign-return-address"="all" "sign-return-address-key"="a_key" {
194 ; COMPAT-LABEL: leaf_sign_all_a_key:
195 ; COMPAT:       // %bb.0:
196 ; COMPAT-NEXT:    hint #25
197 ; COMPAT-NEXT:    .cfi_negate_ra_state
198 ; COMPAT-NEXT:    hint #29
199 ; COMPAT-NEXT:    ret
201 ; V83A-LABEL: leaf_sign_all_a_key:
202 ; V83A:       // %bb.0:
203 ; V83A-NEXT:    paciasp
204 ; V83A-NEXT:    .cfi_negate_ra_state
205 ; V83A-NEXT:    retaa
206   ret i32 %x
209 define i32 @leaf_sign_all_b_key(i32 %x) "sign-return-address"="all" "sign-return-address-key"="b_key" {
210 ; COMPAT-LABEL: leaf_sign_all_b_key:
211 ; COMPAT:       // %bb.0:
212 ; COMPAT-NEXT:    .cfi_b_key_frame
213 ; COMPAT-NEXT:    hint #27
214 ; COMPAT-NEXT:    .cfi_negate_ra_state
215 ; COMPAT-NEXT:    hint #31
216 ; COMPAT-NEXT:    ret
218 ; V83A-LABEL: leaf_sign_all_b_key:
219 ; V83A:       // %bb.0:
220 ; V83A-NEXT:    .cfi_b_key_frame
221 ; V83A-NEXT:    pacibsp
222 ; V83A-NEXT:    .cfi_negate_ra_state
223 ; V83A-NEXT:    retab
224   ret i32 %x
227 define i32 @leaf_sign_all_v83_b_key(i32 %x) "sign-return-address"="all" "target-features"="+v8.3a" "sign-return-address-key"="b_key" {
228 ; CHECK-LABEL: leaf_sign_all_v83_b_key:
229 ; CHECK:       // %bb.0:
230 ; CHECK-NEXT:    .cfi_b_key_frame
231 ; CHECK-NEXT:    pacibsp
232 ; CHECK-NEXT:    .cfi_negate_ra_state
233 ; CHECK-NEXT:    retab
234   ret i32 %x
237 ; Note that BTI instruction is not needed before PACIASP.
238 define i32 @leaf_sign_all_a_key_bti(i32 %x) "sign-return-address"="all" "sign-return-address-key"="a_key" "branch-target-enforcement"="true"{
239 ; COMPAT-LABEL: leaf_sign_all_a_key_bti:
240 ; COMPAT:       // %bb.0:
241 ; COMPAT-NEXT:    hint #25
242 ; COMPAT-NEXT:    .cfi_negate_ra_state
243 ; COMPAT-NEXT:    hint #29
244 ; COMPAT-NEXT:    ret
246 ; V83A-LABEL: leaf_sign_all_a_key_bti:
247 ; V83A:       // %bb.0:
248 ; V83A-NEXT:    paciasp
249 ; V83A-NEXT:    .cfi_negate_ra_state
250 ; V83A-NEXT:    retaa
251   ret i32 %x
254 ; Note that BTI instruction is not needed before PACIBSP.
255 define i32 @leaf_sign_all_b_key_bti(i32 %x) "sign-return-address"="all" "sign-return-address-key"="b_key" "branch-target-enforcement"="true"{
256 ; COMPAT-LABEL: leaf_sign_all_b_key_bti:
257 ; COMPAT:       // %bb.0:
258 ; COMPAT-NEXT:    .cfi_b_key_frame
259 ; COMPAT-NEXT:    hint #27
260 ; COMPAT-NEXT:    .cfi_negate_ra_state
261 ; COMPAT-NEXT:    hint #31
262 ; COMPAT-NEXT:    ret
264 ; V83A-LABEL: leaf_sign_all_b_key_bti:
265 ; V83A:       // %bb.0:
266 ; V83A-NEXT:    .cfi_b_key_frame
267 ; V83A-NEXT:    pacibsp
268 ; V83A-NEXT:    .cfi_negate_ra_state
269 ; V83A-NEXT:    retab
270   ret i32 %x
273 ; Note that BTI instruction is not needed before PACIBSP.
274 define i32 @leaf_sign_all_v83_b_key_bti(i32 %x) "sign-return-address"="all" "target-features"="+v8.3a" "sign-return-address-key"="b_key" "branch-target-enforcement"="true" {
275 ; CHECK-LABEL: leaf_sign_all_v83_b_key_bti:
276 ; CHECK:       // %bb.0:
277 ; CHECK-NEXT:    .cfi_b_key_frame
278 ; CHECK-NEXT:    pacibsp
279 ; CHECK-NEXT:    .cfi_negate_ra_state
280 ; CHECK-NEXT:    retab
281   ret i32 %x