1 ; RUN: opt < %s -inline -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
3 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
5 define i32 @noattr_callee(i32 %i) {
9 define i32 @sanitize_address_callee(i32 %i) sanitize_address {
13 define i32 @sanitize_hwaddress_callee(i32 %i) sanitize_hwaddress {
17 define i32 @sanitize_thread_callee(i32 %i) sanitize_thread {
21 define i32 @sanitize_memory_callee(i32 %i) sanitize_memory {
25 define i32 @sanitize_memtag_callee(i32 %i) sanitize_memtag {
29 define i32 @safestack_callee(i32 %i) safestack {
33 define i32 @slh_callee(i32 %i) speculative_load_hardening {
37 define i32 @alwaysinline_callee(i32 %i) alwaysinline {
41 define i32 @alwaysinline_sanitize_address_callee(i32 %i) alwaysinline sanitize_address {
45 define i32 @alwaysinline_sanitize_hwaddress_callee(i32 %i) alwaysinline sanitize_hwaddress {
49 define i32 @alwaysinline_sanitize_thread_callee(i32 %i) alwaysinline sanitize_thread {
53 define i32 @alwaysinline_sanitize_memory_callee(i32 %i) alwaysinline sanitize_memory {
57 define i32 @alwaysinline_sanitize_memtag_callee(i32 %i) alwaysinline sanitize_memtag {
61 define i32 @alwaysinline_safestack_callee(i32 %i) alwaysinline safestack {
67 ; * noattr callee is inlined into noattr caller,
68 ; * sanitize_(address|memory|thread) callee is not inlined into noattr caller,
69 ; * alwaysinline callee is always inlined no matter what sanitize_* attributes are present.
71 define i32 @test_no_sanitize_address(i32 %arg) {
72 %x1 = call i32 @noattr_callee(i32 %arg)
73 %x2 = call i32 @sanitize_address_callee(i32 %x1)
74 %x3 = call i32 @alwaysinline_callee(i32 %x2)
75 %x4 = call i32 @alwaysinline_sanitize_address_callee(i32 %x3)
77 ; CHECK-LABEL: @test_no_sanitize_address(
78 ; CHECK-NEXT: @sanitize_address_callee
82 define i32 @test_no_sanitize_hwaddress(i32 %arg) {
83 %x1 = call i32 @noattr_callee(i32 %arg)
84 %x2 = call i32 @sanitize_hwaddress_callee(i32 %x1)
85 %x3 = call i32 @alwaysinline_callee(i32 %x2)
86 %x4 = call i32 @alwaysinline_sanitize_hwaddress_callee(i32 %x3)
88 ; CHECK-LABEL: @test_no_sanitize_hwaddress(
89 ; CHECK-NEXT: @sanitize_hwaddress_callee
93 define i32 @test_no_sanitize_memory(i32 %arg) {
94 %x1 = call i32 @noattr_callee(i32 %arg)
95 %x2 = call i32 @sanitize_memory_callee(i32 %x1)
96 %x3 = call i32 @alwaysinline_callee(i32 %x2)
97 %x4 = call i32 @alwaysinline_sanitize_memory_callee(i32 %x3)
99 ; CHECK-LABEL: @test_no_sanitize_memory(
100 ; CHECK-NEXT: @sanitize_memory_callee
101 ; CHECK-NEXT: ret i32
104 define i32 @test_no_sanitize_thread(i32 %arg) {
105 %x1 = call i32 @noattr_callee(i32 %arg)
106 %x2 = call i32 @sanitize_thread_callee(i32 %x1)
107 %x3 = call i32 @alwaysinline_callee(i32 %x2)
108 %x4 = call i32 @alwaysinline_sanitize_thread_callee(i32 %x3)
110 ; CHECK-LABEL: @test_no_sanitize_thread(
111 ; CHECK-NEXT: @sanitize_thread_callee
112 ; CHECK-NEXT: ret i32
115 define i32 @test_no_sanitize_memtag(i32 %arg) {
116 %x1 = call i32 @noattr_callee(i32 %arg)
117 %x2 = call i32 @sanitize_memtag_callee(i32 %x1)
118 %x3 = call i32 @alwaysinline_callee(i32 %x2)
119 %x4 = call i32 @alwaysinline_sanitize_memtag_callee(i32 %x3)
121 ; CHECK-LABEL: @test_no_sanitize_memtag(
122 ; CHECK-NEXT: @sanitize_memtag_callee
123 ; CHECK-NEXT: ret i32
128 ; * noattr callee is not inlined into sanitize_(address|memory|thread) caller,
129 ; * sanitize_(address|memory|thread) callee is inlined into the caller with the same attribute,
130 ; * alwaysinline callee is always inlined no matter what sanitize_* attributes are present.
132 define i32 @test_sanitize_address(i32 %arg) sanitize_address {
133 %x1 = call i32 @noattr_callee(i32 %arg)
134 %x2 = call i32 @sanitize_address_callee(i32 %x1)
135 %x3 = call i32 @alwaysinline_callee(i32 %x2)
136 %x4 = call i32 @alwaysinline_sanitize_address_callee(i32 %x3)
138 ; CHECK-LABEL: @test_sanitize_address(
139 ; CHECK-NEXT: @noattr_callee
140 ; CHECK-NEXT: ret i32
143 define i32 @test_sanitize_hwaddress(i32 %arg) sanitize_hwaddress {
144 %x1 = call i32 @noattr_callee(i32 %arg)
145 %x2 = call i32 @sanitize_hwaddress_callee(i32 %x1)
146 %x3 = call i32 @alwaysinline_callee(i32 %x2)
147 %x4 = call i32 @alwaysinline_sanitize_hwaddress_callee(i32 %x3)
149 ; CHECK-LABEL: @test_sanitize_hwaddress(
150 ; CHECK-NEXT: @noattr_callee
151 ; CHECK-NEXT: ret i32
154 define i32 @test_sanitize_memory(i32 %arg) sanitize_memory {
155 %x1 = call i32 @noattr_callee(i32 %arg)
156 %x2 = call i32 @sanitize_memory_callee(i32 %x1)
157 %x3 = call i32 @alwaysinline_callee(i32 %x2)
158 %x4 = call i32 @alwaysinline_sanitize_memory_callee(i32 %x3)
160 ; CHECK-LABEL: @test_sanitize_memory(
161 ; CHECK-NEXT: @noattr_callee
162 ; CHECK-NEXT: ret i32
165 define i32 @test_sanitize_thread(i32 %arg) sanitize_thread {
166 %x1 = call i32 @noattr_callee(i32 %arg)
167 %x2 = call i32 @sanitize_thread_callee(i32 %x1)
168 %x3 = call i32 @alwaysinline_callee(i32 %x2)
169 %x4 = call i32 @alwaysinline_sanitize_thread_callee(i32 %x3)
171 ; CHECK-LABEL: @test_sanitize_thread(
172 ; CHECK-NEXT: @noattr_callee
173 ; CHECK-NEXT: ret i32
176 define i32 @test_sanitize_memtag(i32 %arg) sanitize_memtag {
177 %x1 = call i32 @noattr_callee(i32 %arg)
178 %x2 = call i32 @sanitize_memtag_callee(i32 %x1)
179 %x3 = call i32 @alwaysinline_callee(i32 %x2)
180 %x4 = call i32 @alwaysinline_sanitize_memtag_callee(i32 %x3)
182 ; CHECK-LABEL: @test_sanitize_memtag(
183 ; CHECK-NEXT: @noattr_callee
184 ; CHECK-NEXT: ret i32
187 define i32 @test_safestack(i32 %arg) safestack {
188 %x1 = call i32 @noattr_callee(i32 %arg)
189 %x2 = call i32 @safestack_callee(i32 %x1)
190 %x3 = call i32 @alwaysinline_callee(i32 %x2)
191 %x4 = call i32 @alwaysinline_safestack_callee(i32 %x3)
193 ; CHECK-LABEL: @test_safestack(
194 ; CHECK-NEXT: @noattr_callee
195 ; CHECK-NEXT: ret i32
198 ; Can inline a normal function into an SLH'ed function.
199 define i32 @test_caller_slh(i32 %i) speculative_load_hardening {
200 ; CHECK-LABEL: @test_caller_slh(
201 ; CHECK-SAME: ) [[SLH:.*]] {
205 %callee = call i32 @noattr_callee(i32 %i)
209 ; Can inline a SLH'ed function into a normal one, propagating SLH.
210 define i32 @test_callee_slh(i32 %i) {
211 ; CHECK-LABEL: @test_callee_slh(
212 ; CHECK-SAME: ) [[SLH:.*]] {
216 %callee = call i32 @slh_callee(i32 %i)
220 ; Check that a function doesn't get inlined if target-cpu strings don't match
222 define i32 @test_target_cpu_callee0(i32 %i) "target-cpu"="corei7" {
226 define i32 @test_target_cpu0(i32 %i) "target-cpu"="corei7" {
227 %1 = call i32 @test_target_cpu_callee0(i32 %i)
229 ; CHECK-LABEL: @test_target_cpu0(
230 ; CHECK-NOT: @test_target_cpu_callee0
233 define i32 @test_target_cpu_callee1(i32 %i) "target-cpu"="x86-64" {
237 define i32 @test_target_cpu1(i32 %i) "target-cpu"="corei7" {
238 %1 = call i32 @test_target_cpu_callee1(i32 %i)
240 ; CHECK-LABEL: @test_target_cpu1(
241 ; CHECK-NEXT: @test_target_cpu_callee1
242 ; CHECK-NEXT: ret i32
245 ; Check that a function doesn't get inlined if target-features strings don't
247 define i32 @test_target_features_callee0(i32 %i) "target-features"="+sse4.2" {
251 define i32 @test_target_features0(i32 %i) "target-features"="+sse4.2" {
252 %1 = call i32 @test_target_features_callee0(i32 %i)
254 ; CHECK-LABEL: @test_target_features0(
255 ; CHECK-NOT: @test_target_features_callee0
258 define i32 @test_target_features_callee1(i32 %i) "target-features"="+avx2" {
262 define i32 @test_target_features1(i32 %i) "target-features"="+sse4.2" {
263 %1 = call i32 @test_target_features_callee1(i32 %i)
265 ; CHECK-LABEL: @test_target_features1(
266 ; CHECK-NEXT: @test_target_features_callee1
267 ; CHECK-NEXT: ret i32
270 define i32 @less-precise-fpmad_callee0(i32 %i) "less-precise-fpmad"="false" {
272 ; CHECK: @less-precise-fpmad_callee0(i32 %i) [[FPMAD_FALSE:#[0-9]+]] {
273 ; CHECK-NEXT: ret i32
276 define i32 @less-precise-fpmad_callee1(i32 %i) "less-precise-fpmad"="true" {
278 ; CHECK: @less-precise-fpmad_callee1(i32 %i) [[FPMAD_TRUE:#[0-9]+]] {
279 ; CHECK-NEXT: ret i32
282 define i32 @test_less-precise-fpmad0(i32 %i) "less-precise-fpmad"="false" {
283 %1 = call i32 @less-precise-fpmad_callee0(i32 %i)
285 ; CHECK: @test_less-precise-fpmad0(i32 %i) [[FPMAD_FALSE]] {
286 ; CHECK-NEXT: ret i32
289 define i32 @test_less-precise-fpmad1(i32 %i) "less-precise-fpmad"="false" {
290 %1 = call i32 @less-precise-fpmad_callee1(i32 %i)
292 ; CHECK: @test_less-precise-fpmad1(i32 %i) [[FPMAD_FALSE]] {
293 ; CHECK-NEXT: ret i32
296 define i32 @test_less-precise-fpmad2(i32 %i) "less-precise-fpmad"="true" {
297 %1 = call i32 @less-precise-fpmad_callee0(i32 %i)
299 ; CHECK: @test_less-precise-fpmad2(i32 %i) [[FPMAD_FALSE]] {
300 ; CHECK-NEXT: ret i32
303 define i32 @test_less-precise-fpmad3(i32 %i) "less-precise-fpmad"="true" {
304 %1 = call i32 @less-precise-fpmad_callee1(i32 %i)
306 ; CHECK: @test_less-precise-fpmad3(i32 %i) [[FPMAD_TRUE]] {
307 ; CHECK-NEXT: ret i32
310 define i32 @no-implicit-float_callee0(i32 %i) {
312 ; CHECK: @no-implicit-float_callee0(i32 %i) {
313 ; CHECK-NEXT: ret i32
316 define i32 @no-implicit-float_callee1(i32 %i) noimplicitfloat {
318 ; CHECK: @no-implicit-float_callee1(i32 %i) [[NOIMPLICITFLOAT:#[0-9]+]] {
319 ; CHECK-NEXT: ret i32
322 define i32 @test_no-implicit-float0(i32 %i) {
323 %1 = call i32 @no-implicit-float_callee0(i32 %i)
325 ; CHECK: @test_no-implicit-float0(i32 %i) {
326 ; CHECK-NEXT: ret i32
329 define i32 @test_no-implicit-float1(i32 %i) {
330 %1 = call i32 @no-implicit-float_callee1(i32 %i)
332 ; CHECK: @test_no-implicit-float1(i32 %i) [[NOIMPLICITFLOAT]] {
333 ; CHECK-NEXT: ret i32
336 define i32 @test_no-implicit-float2(i32 %i) noimplicitfloat {
337 %1 = call i32 @no-implicit-float_callee0(i32 %i)
339 ; CHECK: @test_no-implicit-float2(i32 %i) [[NOIMPLICITFLOAT]] {
340 ; CHECK-NEXT: ret i32
343 define i32 @test_no-implicit-float3(i32 %i) noimplicitfloat {
344 %1 = call i32 @no-implicit-float_callee1(i32 %i)
346 ; CHECK: @test_no-implicit-float3(i32 %i) [[NOIMPLICITFLOAT]] {
347 ; CHECK-NEXT: ret i32
350 ; Check that no-jump-tables flag propagates from inlined callee to caller
352 define i32 @no-use-jump-tables_callee0(i32 %i) {
354 ; CHECK: @no-use-jump-tables_callee0(i32 %i) {
355 ; CHECK-NEXT: ret i32
358 define i32 @no-use-jump-tables_callee1(i32 %i) "no-jump-tables"="true" {
360 ; CHECK: @no-use-jump-tables_callee1(i32 %i) [[NOUSEJUMPTABLES:#[0-9]+]] {
361 ; CHECK-NEXT: ret i32
364 define i32 @test_no-use-jump-tables0(i32 %i) {
365 %1 = call i32 @no-use-jump-tables_callee0(i32 %i)
367 ; CHECK: @test_no-use-jump-tables0(i32 %i) {
368 ; CHECK-NEXT: ret i32
371 define i32 @test_no-use-jump-tables1(i32 %i) {
372 %1 = call i32 @no-use-jump-tables_callee1(i32 %i)
374 ; CHECK: @test_no-use-jump-tables1(i32 %i) [[NOUSEJUMPTABLES]] {
375 ; CHECK-NEXT: ret i32
378 define i32 @test_no-use-jump-tables2(i32 %i) "no-jump-tables"="true" {
379 %1 = call i32 @no-use-jump-tables_callee0(i32 %i)
381 ; CHECK: @test_no-use-jump-tables2(i32 %i) [[NOUSEJUMPTABLES]] {
382 ; CHECK-NEXT: ret i32
385 define i32 @test_no-use-jump-tables3(i32 %i) "no-jump-tables"="true" {
386 %1 = call i32 @no-use-jump-tables_callee1(i32 %i)
388 ; CHECK: @test_no-use-jump-tables3(i32 %i) [[NOUSEJUMPTABLES]] {
389 ; CHECK-NEXT: ret i32
392 ; Callee with "null-pointer-is-valid"="true" attribute should not be inlined
393 ; into a caller without this attribute.
394 ; Exception: alwaysinline callee can still be inlined but
395 ; "null-pointer-is-valid"="true" should get copied to caller.
397 define i32 @null-pointer-is-valid_callee0(i32 %i) "null-pointer-is-valid"="true" {
399 ; CHECK: @null-pointer-is-valid_callee0(i32 %i)
400 ; CHECK-NEXT: ret i32
403 define i32 @null-pointer-is-valid_callee1(i32 %i) alwaysinline "null-pointer-is-valid"="true" {
405 ; CHECK: @null-pointer-is-valid_callee1(i32 %i)
406 ; CHECK-NEXT: ret i32
409 define i32 @null-pointer-is-valid_callee2(i32 %i) {
411 ; CHECK: @null-pointer-is-valid_callee2(i32 %i)
412 ; CHECK-NEXT: ret i32
415 ; No inlining since caller does not have "null-pointer-is-valid"="true" attribute.
416 define i32 @test_null-pointer-is-valid0(i32 %i) {
417 %1 = call i32 @null-pointer-is-valid_callee0(i32 %i)
419 ; CHECK: @test_null-pointer-is-valid0(
420 ; CHECK: call i32 @null-pointer-is-valid_callee0
421 ; CHECK-NEXT: ret i32
424 ; alwaysinline should force inlining even when caller does not have
425 ; "null-pointer-is-valid"="true" attribute. However, the attribute should be
427 define i32 @test_null-pointer-is-valid1(i32 %i) "null-pointer-is-valid"="false" {
428 %1 = call i32 @null-pointer-is-valid_callee1(i32 %i)
430 ; CHECK: @test_null-pointer-is-valid1(i32 %i) [[NULLPOINTERISVALID:#[0-9]+]] {
431 ; CHECK-NEXT: ret i32
434 ; Can inline since both caller and callee have "null-pointer-is-valid"="true"
436 define i32 @test_null-pointer-is-valid2(i32 %i) "null-pointer-is-valid"="true" {
437 %1 = call i32 @null-pointer-is-valid_callee2(i32 %i)
439 ; CHECK: @test_null-pointer-is-valid2(i32 %i) [[NULLPOINTERISVALID]] {
440 ; CHECK-NEXT: ret i32
443 ; CHECK: attributes [[SLH]] = { speculative_load_hardening }
444 ; CHECK: attributes [[FPMAD_FALSE]] = { "less-precise-fpmad"="false" }
445 ; CHECK: attributes [[FPMAD_TRUE]] = { "less-precise-fpmad"="true" }
446 ; CHECK: attributes [[NOIMPLICITFLOAT]] = { noimplicitfloat }
447 ; CHECK: attributes [[NOUSEJUMPTABLES]] = { "no-jump-tables"="true" }
448 ; CHECK: attributes [[NULLPOINTERISVALID]] = { "null-pointer-is-valid"="true" }