1 ; RUN: llc -mtriple=x86_64-apple-macosx -O3 -debug-only=faultmaps -enable-implicit-null-checks < %s 2>&1 | FileCheck %s
4 ; List cases where we should *not* be emitting implicit null checks.
6 ; CHECK-NOT: Fault Map Output
8 define i32 @imp_null_check_load(ptr %x, ptr %y) {
10 %c = icmp eq ptr %x, null
11 ; It isn't legal to move the load from %x from "not_null" to here --
12 ; the store to %y could be aliasing it.
13 br i1 %c, label %is_null, label %not_null, !make.implicit !0
24 define i32 @imp_null_check_gep_load(ptr %x) {
26 %c = icmp eq ptr %x, null
27 br i1 %c, label %is_null, label %not_null, !make.implicit !0
33 ; null + 5000 * sizeof(i32) lies outside the null page and hence the
34 ; load to %t cannot be assumed to be reliably faulting.
35 %x.gep = getelementptr i32, ptr %x, i32 5000
36 %t = load i32, ptr %x.gep
40 define i32 @imp_null_check_neg_gep_load(ptr %x) {
42 %c = icmp eq ptr %x, null
43 br i1 %c, label %is_null, label %not_null, !make.implicit !0
49 ; null - 5000 * sizeof(i32) lies outside the null page and hence the
50 ; load to %t cannot be assumed to be reliably faulting.
51 %x.gep = getelementptr i32, ptr %x, i32 -5000
52 %t = load i32, ptr %x.gep
56 define i32 @imp_null_check_load_no_md(ptr %x) {
57 ; This is fine, except it is missing the !make.implicit metadata.
59 %c = icmp eq ptr %x, null
60 br i1 %c, label %is_null, label %not_null
70 define i32 @imp_null_check_no_hoist_over_acquire_load(ptr %x, ptr %y) {
71 ; We cannot hoist %t1 over %t0 since %t0 is an acquire load
73 %c = icmp eq ptr %x, null
74 br i1 %c, label %is_null, label %not_null, !make.implicit !0
80 %t0 = load atomic i32, ptr %y acquire, align 4
81 %t1 = load i32, ptr %x
86 define i32 @imp_null_check_add_result(ptr %x, ptr %y) {
87 ; This will codegen to:
92 ; The load instruction we wish to hoist is the addl, but there is a
93 ; write-after-write hazard preventing that from happening. We could
94 ; get fancy here and exploit the commutativity of addition, but right
95 ; now -implicit-null-checks isn't that smart.
99 %c = icmp eq ptr %x, null
100 br i1 %c, label %is_null, label %not_null, !make.implicit !0
106 %t0 = load i32, ptr %y
107 %t1 = load i32, ptr %x
108 %p = add i32 %t0, %t1
112 ; This redefines the null check reg by doing a zero-extend, a shift on
113 ; itself and then an add.
114 ; Cannot be converted to implicit check since the zero reg is no longer zero.
115 define i64 @imp_null_check_load_shift_add_addr(ptr %x, i64 %r) {
117 %c = icmp eq ptr %x, null
118 br i1 %c, label %is_null, label %not_null, !make.implicit !0
124 %y = ptrtoint ptr %x to i64
125 %shry = shl i64 %y, 6
126 %shry.add = add i64 %shry, %r
127 %y.ptr = inttoptr i64 %shry.add to ptr
128 %x.loc = getelementptr i64, ptr %y.ptr, i64 1
129 %t = load i64, ptr %x.loc
133 ; the memory op is not within faulting page.
134 define i64 @imp_null_check_load_addr_outside_faulting_page(ptr %x) {
136 %c = icmp eq ptr %x, null
137 br i1 %c, label %is_null, label %not_null, !make.implicit !0
143 %y = ptrtoint ptr %x to i64
144 %shry = shl i64 %y, 3
145 %shry.add = add i64 %shry, 68719472640
146 %y.ptr = inttoptr i64 %shry.add to ptr
147 %x.loc = getelementptr i64, ptr %y.ptr, i64 1
148 %t = load i64, ptr %x.loc