1; RUN: llc -mtriple=x86_64-apple-macosx -O3 -debug-only=faultmaps -enable-implicit-null-checks < %s 2>&1 | FileCheck %s 2; REQUIRES: asserts 3 4; List cases where we should *not* be emitting implicit null checks. 5 6; CHECK-NOT: Fault Map Output 7 8define i32 @imp_null_check_load(i32* %x, i32* %y) { 9 entry: 10 %c = icmp eq i32* %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 14 15 is_null: 16 ret i32 42 17 18 not_null: 19 store i32 0, i32* %y 20 %t = load i32, i32* %x 21 ret i32 %t 22} 23 24define i32 @imp_null_check_gep_load(i32* %x) { 25 entry: 26 %c = icmp eq i32* %x, null 27 br i1 %c, label %is_null, label %not_null, !make.implicit !0 28 29 is_null: 30 ret i32 42 31 32 not_null: 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, i32* %x, i32 5000 36 %t = load i32, i32* %x.gep 37 ret i32 %t 38} 39 40define i32 @imp_null_check_load_no_md(i32* %x) { 41; This is fine, except it is missing the !make.implicit metadata. 42 entry: 43 %c = icmp eq i32* %x, null 44 br i1 %c, label %is_null, label %not_null 45 46 is_null: 47 ret i32 42 48 49 not_null: 50 %t = load i32, i32* %x 51 ret i32 %t 52} 53 54define i32 @imp_null_check_no_hoist_over_acquire_load(i32* %x, i32* %y) { 55; We cannot hoist %t1 over %t0 since %t0 is an acquire load 56 entry: 57 %c = icmp eq i32* %x, null 58 br i1 %c, label %is_null, label %not_null, !make.implicit !0 59 60 is_null: 61 ret i32 42 62 63 not_null: 64 %t0 = load atomic i32, i32* %y acquire, align 4 65 %t1 = load i32, i32* %x 66 %p = add i32 %t0, %t1 67 ret i32 %p 68} 69 70define i32 @imp_null_check_add_result(i32* %x, i32* %y) { 71; This will codegen to: 72; 73; movl (%rsi), %eax 74; addl (%rdi), %eax 75; 76; The load instruction we wish to hoist is the addl, but there is a 77; write-after-write hazard preventing that from happening. We could 78; get fancy here and exploit the commutativity of addition, but right 79; now -implicit-null-checks isn't that smart. 80; 81 82 entry: 83 %c = icmp eq i32* %x, null 84 br i1 %c, label %is_null, label %not_null, !make.implicit !0 85 86 is_null: 87 ret i32 42 88 89 not_null: 90 %t0 = load i32, i32* %y 91 %t1 = load i32, i32* %x 92 %p = add i32 %t0, %t1 93 ret i32 %p 94} 95 96!0 = !{} 97