1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs -O3 -mtriple=x86_64-apple-macosx -enable-implicit-null-checks < %s | FileCheck %s
4 define i32 @imp_null_check_load(i32* %x) {
5 ; CHECK-LABEL: imp_null_check_load:
6 ; CHECK: ## %bb.0: ## %entry
8 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB0_1
9 ; CHECK-NEXT: ## %bb.2: ## %not_null
11 ; CHECK-NEXT: LBB0_1: ## %is_null
12 ; CHECK-NEXT: movl $42, %eax
16 %c = icmp eq i32* %x, null
17 br i1 %c, label %is_null, label %not_null, !make.implicit !0
23 %t = load i32, i32* %x
27 ; TODO: can make implicit
28 define i32 @imp_null_check_unordered_load(i32* %x) {
29 ; CHECK-LABEL: imp_null_check_unordered_load:
30 ; CHECK: ## %bb.0: ## %entry
32 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB1_1
33 ; CHECK-NEXT: ## %bb.2: ## %not_null
35 ; CHECK-NEXT: LBB1_1: ## %is_null
36 ; CHECK-NEXT: movl $42, %eax
40 %c = icmp eq i32* %x, null
41 br i1 %c, label %is_null, label %not_null, !make.implicit !0
47 %t = load atomic i32, i32* %x unordered, align 4
51 ;; Probably could be implicit, but we're conservative for now
52 define i32 @imp_null_check_seq_cst_load(i32* %x) {
53 ; CHECK-LABEL: imp_null_check_seq_cst_load:
54 ; CHECK: ## %bb.0: ## %entry
55 ; CHECK-NEXT: testq %rdi, %rdi
56 ; CHECK-NEXT: je LBB2_1
57 ; CHECK-NEXT: ## %bb.2: ## %not_null
58 ; CHECK-NEXT: movl (%rdi), %eax
60 ; CHECK-NEXT: LBB2_1: ## %is_null
61 ; CHECK-NEXT: movl $42, %eax
65 %c = icmp eq i32* %x, null
66 br i1 %c, label %is_null, label %not_null, !make.implicit !0
72 %t = load atomic i32, i32* %x seq_cst, align 4
76 ;; Might be memory mapped IO, so can't rely on fault behavior
77 define i32 @imp_null_check_volatile_load(i32* %x) {
78 ; CHECK-LABEL: imp_null_check_volatile_load:
79 ; CHECK: ## %bb.0: ## %entry
80 ; CHECK-NEXT: testq %rdi, %rdi
81 ; CHECK-NEXT: je LBB3_1
82 ; CHECK-NEXT: ## %bb.2: ## %not_null
83 ; CHECK-NEXT: movl (%rdi), %eax
85 ; CHECK-NEXT: LBB3_1: ## %is_null
86 ; CHECK-NEXT: movl $42, %eax
90 %c = icmp eq i32* %x, null
91 br i1 %c, label %is_null, label %not_null, !make.implicit !0
97 %t = load volatile i32, i32* %x, align 4
102 define i8 @imp_null_check_load_i8(i8* %x) {
103 ; CHECK-LABEL: imp_null_check_load_i8:
104 ; CHECK: ## %bb.0: ## %entry
106 ; CHECK-NEXT: movb (%rdi), %al ## on-fault: LBB4_1
107 ; CHECK-NEXT: ## %bb.2: ## %not_null
109 ; CHECK-NEXT: LBB4_1: ## %is_null
110 ; CHECK-NEXT: movb $42, %al
114 %c = icmp eq i8* %x, null
115 br i1 %c, label %is_null, label %not_null, !make.implicit !0
125 define i256 @imp_null_check_load_i256(i256* %x) {
126 ; CHECK-LABEL: imp_null_check_load_i256:
127 ; CHECK: ## %bb.0: ## %entry
128 ; CHECK-NEXT: movq %rdi, %rax
130 ; CHECK-NEXT: movq (%rsi), %rcx ## on-fault: LBB5_1
131 ; CHECK-NEXT: ## %bb.2: ## %not_null
132 ; CHECK-NEXT: movq 8(%rsi), %rdx
133 ; CHECK-NEXT: movq 16(%rsi), %rdi
134 ; CHECK-NEXT: movq 24(%rsi), %rsi
135 ; CHECK-NEXT: movq %rsi, 24(%rax)
136 ; CHECK-NEXT: movq %rdi, 16(%rax)
137 ; CHECK-NEXT: movq %rdx, 8(%rax)
138 ; CHECK-NEXT: movq %rcx, (%rax)
140 ; CHECK-NEXT: LBB5_1: ## %is_null
141 ; CHECK-NEXT: movq $0, 24(%rax)
142 ; CHECK-NEXT: movq $0, 16(%rax)
143 ; CHECK-NEXT: movq $0, 8(%rax)
144 ; CHECK-NEXT: movq $42, (%rax)
148 %c = icmp eq i256* %x, null
149 br i1 %c, label %is_null, label %not_null, !make.implicit !0
155 %t = load i256, i256* %x
161 define i32 @imp_null_check_gep_load(i32* %x) {
162 ; CHECK-LABEL: imp_null_check_gep_load:
163 ; CHECK: ## %bb.0: ## %entry
165 ; CHECK-NEXT: movl 128(%rdi), %eax ## on-fault: LBB6_1
166 ; CHECK-NEXT: ## %bb.2: ## %not_null
168 ; CHECK-NEXT: LBB6_1: ## %is_null
169 ; CHECK-NEXT: movl $42, %eax
173 %c = icmp eq i32* %x, null
174 br i1 %c, label %is_null, label %not_null, !make.implicit !0
180 %x.gep = getelementptr i32, i32* %x, i32 32
181 %t = load i32, i32* %x.gep
185 define i32 @imp_null_check_add_result(i32* %x, i32 %p) {
186 ; CHECK-LABEL: imp_null_check_add_result:
187 ; CHECK: ## %bb.0: ## %entry
189 ; CHECK-NEXT: addl (%rdi), %esi ## on-fault: LBB7_1
190 ; CHECK-NEXT: ## %bb.2: ## %not_null
191 ; CHECK-NEXT: movl %esi, %eax
193 ; CHECK-NEXT: LBB7_1: ## %is_null
194 ; CHECK-NEXT: movl $42, %eax
198 %c = icmp eq i32* %x, null
199 br i1 %c, label %is_null, label %not_null, !make.implicit !0
205 %t = load i32, i32* %x
210 define i32 @imp_null_check_sub_result(i32* %x, i32 %p) {
211 ; CHECK-LABEL: imp_null_check_sub_result:
212 ; CHECK: ## %bb.0: ## %entry
214 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB8_1
215 ; CHECK-NEXT: ## %bb.2: ## %not_null
216 ; CHECK-NEXT: subl %esi, %eax
218 ; CHECK-NEXT: LBB8_1: ## %is_null
219 ; CHECK-NEXT: movl $42, %eax
223 %c = icmp eq i32* %x, null
224 br i1 %c, label %is_null, label %not_null, !make.implicit !0
230 %t = load i32, i32* %x
235 define i32 @imp_null_check_mul_result(i32* %x, i32 %p) {
236 ; CHECK-LABEL: imp_null_check_mul_result:
237 ; CHECK: ## %bb.0: ## %entry
239 ; CHECK-NEXT: imull (%rdi), %esi ## on-fault: LBB9_1
240 ; CHECK-NEXT: ## %bb.2: ## %not_null
241 ; CHECK-NEXT: movl %esi, %eax
243 ; CHECK-NEXT: LBB9_1: ## %is_null
244 ; CHECK-NEXT: movl $42, %eax
248 %c = icmp eq i32* %x, null
249 br i1 %c, label %is_null, label %not_null, !make.implicit !0
255 %t = load i32, i32* %x
260 define i32 @imp_null_check_udiv_result(i32* %x, i32 %p) {
261 ; CHECK-LABEL: imp_null_check_udiv_result:
262 ; CHECK: ## %bb.0: ## %entry
264 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB10_1
265 ; CHECK-NEXT: ## %bb.2: ## %not_null
266 ; CHECK-NEXT: xorl %edx, %edx
267 ; CHECK-NEXT: divl %esi
269 ; CHECK-NEXT: LBB10_1: ## %is_null
270 ; CHECK-NEXT: movl $42, %eax
274 %c = icmp eq i32* %x, null
275 br i1 %c, label %is_null, label %not_null, !make.implicit !0
281 %t = load i32, i32* %x
282 %p1 = udiv i32 %t, %p
286 define i32 @imp_null_check_shl_result(i32* %x, i32 %p) {
287 ; CHECK-LABEL: imp_null_check_shl_result:
288 ; CHECK: ## %bb.0: ## %entry
290 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB11_1
291 ; CHECK-NEXT: ## %bb.2: ## %not_null
292 ; CHECK-NEXT: movl %esi, %ecx
293 ; CHECK-NEXT: shll %cl, %eax
295 ; CHECK-NEXT: LBB11_1: ## %is_null
296 ; CHECK-NEXT: movl $42, %eax
300 %c = icmp eq i32* %x, null
301 br i1 %c, label %is_null, label %not_null, !make.implicit !0
307 %t = load i32, i32* %x
312 define i32 @imp_null_check_lshr_result(i32* %x, i32 %p) {
313 ; CHECK-LABEL: imp_null_check_lshr_result:
314 ; CHECK: ## %bb.0: ## %entry
315 ; CHECK-NEXT: Ltmp10:
316 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB12_1
317 ; CHECK-NEXT: ## %bb.2: ## %not_null
318 ; CHECK-NEXT: movl %esi, %ecx
319 ; CHECK-NEXT: shrl %cl, %eax
321 ; CHECK-NEXT: LBB12_1: ## %is_null
322 ; CHECK-NEXT: movl $42, %eax
326 %c = icmp eq i32* %x, null
327 br i1 %c, label %is_null, label %not_null, !make.implicit !0
333 %t = load i32, i32* %x
334 %p1 = lshr i32 %t, %p
341 define i32 @imp_null_check_hoist_over_unrelated_load(i32* %x, i32* %y, i32* %z) {
342 ; CHECK-LABEL: imp_null_check_hoist_over_unrelated_load:
343 ; CHECK: ## %bb.0: ## %entry
344 ; CHECK-NEXT: Ltmp11:
345 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB13_1
346 ; CHECK-NEXT: ## %bb.2: ## %not_null
347 ; CHECK-NEXT: movl (%rsi), %ecx
348 ; CHECK-NEXT: movl %ecx, (%rdx)
350 ; CHECK-NEXT: LBB13_1: ## %is_null
351 ; CHECK-NEXT: movl $42, %eax
355 %c = icmp eq i32* %x, null
356 br i1 %c, label %is_null, label %not_null, !make.implicit !0
362 %t0 = load i32, i32* %y
363 %t1 = load i32, i32* %x
364 store i32 %t0, i32* %z
368 define i32 @imp_null_check_via_mem_comparision(i32* %x, i32 %val) {
369 ; CHECK-LABEL: imp_null_check_via_mem_comparision:
370 ; CHECK: ## %bb.0: ## %entry
371 ; CHECK-NEXT: Ltmp12:
372 ; CHECK-NEXT: cmpl %esi, 4(%rdi) ## on-fault: LBB14_3
373 ; CHECK-NEXT: ## %bb.1: ## %not_null
374 ; CHECK-NEXT: jge LBB14_2
375 ; CHECK-NEXT: ## %bb.4: ## %ret_100
376 ; CHECK-NEXT: movl $100, %eax
378 ; CHECK-NEXT: LBB14_3: ## %is_null
379 ; CHECK-NEXT: movl $42, %eax
381 ; CHECK-NEXT: LBB14_2: ## %ret_200
382 ; CHECK-NEXT: movl $200, %eax
386 %c = icmp eq i32* %x, null
387 br i1 %c, label %is_null, label %not_null, !make.implicit !0
393 %x.loc = getelementptr i32, i32* %x, i32 1
394 %t = load i32, i32* %x.loc
395 %m = icmp slt i32 %t, %val
396 br i1 %m, label %ret_100, label %ret_200
405 define i32 @imp_null_check_gep_load_with_use_dep(i32* %x, i32 %a) {
406 ; CHECK-LABEL: imp_null_check_gep_load_with_use_dep:
407 ; CHECK: ## %bb.0: ## %entry
408 ; CHECK-NEXT: ## kill: def $esi killed $esi def $rsi
409 ; CHECK-NEXT: Ltmp13:
410 ; CHECK-NEXT: movl (%rdi), %eax ## on-fault: LBB15_1
411 ; CHECK-NEXT: ## %bb.2: ## %not_null
412 ; CHECK-NEXT: addl %edi, %esi
413 ; CHECK-NEXT: leal 4(%rax,%rsi), %eax
415 ; CHECK-NEXT: LBB15_1: ## %is_null
416 ; CHECK-NEXT: movl $42, %eax
420 %c = icmp eq i32* %x, null
421 br i1 %c, label %is_null, label %not_null, !make.implicit !0
427 %x.loc = getelementptr i32, i32* %x, i32 1
428 %y = ptrtoint i32* %x.loc to i32
430 %t = load i32, i32* %x
435 ;; TODO: We could handle this case as we can lift the fence into the
436 ;; previous block before the conditional without changing behavior.
437 define i32 @imp_null_check_load_fence1(i32* %x) {
438 ; CHECK-LABEL: imp_null_check_load_fence1:
439 ; CHECK: ## %bb.0: ## %entry
440 ; CHECK-NEXT: testq %rdi, %rdi
441 ; CHECK-NEXT: je LBB16_1
442 ; CHECK-NEXT: ## %bb.2: ## %not_null
443 ; CHECK-NEXT: ##MEMBARRIER
444 ; CHECK-NEXT: movl (%rdi), %eax
446 ; CHECK-NEXT: LBB16_1: ## %is_null
447 ; CHECK-NEXT: movl $42, %eax
451 %c = icmp eq i32* %x, null
452 br i1 %c, label %is_null, label %not_null, !make.implicit !0
459 %t = load i32, i32* %x
463 ;; TODO: We could handle this case as we can lift the fence into the
464 ;; previous block before the conditional without changing behavior.
465 define i32 @imp_null_check_load_fence2(i32* %x) {
466 ; CHECK-LABEL: imp_null_check_load_fence2:
467 ; CHECK: ## %bb.0: ## %entry
468 ; CHECK-NEXT: testq %rdi, %rdi
469 ; CHECK-NEXT: je LBB17_1
470 ; CHECK-NEXT: ## %bb.2: ## %not_null
472 ; CHECK-NEXT: movl (%rdi), %eax
474 ; CHECK-NEXT: LBB17_1: ## %is_null
475 ; CHECK-NEXT: movl $42, %eax
479 %c = icmp eq i32* %x, null
480 br i1 %c, label %is_null, label %not_null, !make.implicit !0
487 %t = load i32, i32* %x
491 define void @imp_null_check_store(i32* %x) {
492 ; CHECK-LABEL: imp_null_check_store:
493 ; CHECK: ## %bb.0: ## %entry
494 ; CHECK-NEXT: Ltmp14:
495 ; CHECK-NEXT: movl $1, (%rdi) ## on-fault: LBB18_1
496 ; CHECK-NEXT: ## %bb.2: ## %not_null
498 ; CHECK-NEXT: LBB18_1: ## %is_null
502 %c = icmp eq i32* %x, null
503 br i1 %c, label %is_null, label %not_null, !make.implicit !0
513 ;; TODO: can be implicit
514 define void @imp_null_check_unordered_store(i32* %x) {
515 ; CHECK-LABEL: imp_null_check_unordered_store:
516 ; CHECK: ## %bb.0: ## %entry
517 ; CHECK-NEXT: Ltmp15:
518 ; CHECK-NEXT: movl $1, (%rdi) ## on-fault: LBB19_1
519 ; CHECK-NEXT: ## %bb.2: ## %not_null
521 ; CHECK-NEXT: LBB19_1: ## %is_null
525 %c = icmp eq i32* %x, null
526 br i1 %c, label %is_null, label %not_null, !make.implicit !0
532 store atomic i32 1, i32* %x unordered, align 4
536 define i32 @imp_null_check_neg_gep_load(i32* %x) {
537 ; CHECK-LABEL: imp_null_check_neg_gep_load:
538 ; CHECK: ## %bb.0: ## %entry
539 ; CHECK-NEXT: Ltmp16:
540 ; CHECK-NEXT: movl -128(%rdi), %eax ## on-fault: LBB20_1
541 ; CHECK-NEXT: ## %bb.2: ## %not_null
543 ; CHECK-NEXT: LBB20_1: ## %is_null
544 ; CHECK-NEXT: movl $42, %eax
548 %c = icmp eq i32* %x, null
549 br i1 %c, label %is_null, label %not_null, !make.implicit !0
555 %x.gep = getelementptr i32, i32* %x, i32 -32
556 %t = load i32, i32* %x.gep