brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 59e4f17 Raw
153 lines · plain
1; RUN: llc -mtriple=x86_64-apple-macosx -O3 -debug-only=faultmaps -enable-implicit-null-checks < %s 2>&1 | FileCheck %s2; REQUIRES: asserts3 4; List cases where we should *not* be emitting implicit null checks.5 6; CHECK-NOT: Fault Map Output7 8define i32 @imp_null_check_load(ptr %x, ptr %y) {9 entry:10  %c = icmp eq ptr %x, null11; 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 !014 15 is_null:16  ret i32 4217 18 not_null:19  store i32 0, ptr %y20  %t = load i32, ptr %x21  ret i32 %t22}23 24define i32 @imp_null_check_gep_load(ptr %x) {25 entry:26  %c = icmp eq ptr %x, null27  br i1 %c, label %is_null, label %not_null, !make.implicit !028 29 is_null:30  ret i32 4231 32 not_null:33; null + 5000 * sizeof(i32) lies outside the null page and hence the34; load to %t cannot be assumed to be reliably faulting.35  %x.gep = getelementptr i32, ptr %x, i32 500036  %t = load i32, ptr %x.gep37  ret i32 %t38}39 40define i32 @imp_null_check_neg_gep_load(ptr %x) {41 entry:42  %c = icmp eq ptr %x, null43  br i1 %c, label %is_null, label %not_null, !make.implicit !044 45 is_null:46  ret i32 4247 48 not_null:49; null - 5000 * sizeof(i32) lies outside the null page and hence the50; load to %t cannot be assumed to be reliably faulting.51  %x.gep = getelementptr i32, ptr %x, i32 -500052  %t = load i32, ptr %x.gep53  ret i32 %t54}55 56define i32 @imp_null_check_load_no_md(ptr %x) {57; This is fine, except it is missing the !make.implicit metadata.58 entry:59  %c = icmp eq ptr %x, null60  br i1 %c, label %is_null, label %not_null61 62 is_null:63  ret i32 4264 65 not_null:66  %t = load i32, ptr %x67  ret i32 %t68}69 70define 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 load72 entry:73  %c = icmp eq ptr %x, null74  br i1 %c, label %is_null, label %not_null, !make.implicit !075 76 is_null:77  ret i32 4278 79 not_null:80  %t0 = load atomic i32, ptr %y acquire, align 481  %t1 = load i32, ptr %x82  %p = add i32 %t0, %t183  ret i32 %p84}85 86define i32 @imp_null_check_add_result(ptr %x, ptr %y) {87; This will codegen to:88;89;   movl    (%rsi), %eax90;   addl    (%rdi), %eax91;92; The load instruction we wish to hoist is the addl, but there is a93; write-after-write hazard preventing that from happening.  We could94; get fancy here and exploit the commutativity of addition, but right95; now -implicit-null-checks isn't that smart.96;97 98 entry:99  %c = icmp eq ptr %x, null100  br i1 %c, label %is_null, label %not_null, !make.implicit !0101 102 is_null:103  ret i32 42104 105 not_null:106  %t0 = load i32, ptr %y107  %t1 = load i32, ptr %x108  %p = add i32 %t0, %t1109  ret i32 %p110}111 112; This redefines the null check reg by doing a zero-extend, a shift on113; itself and then an add.114; Cannot be converted to implicit check since the zero reg is no longer zero.115define i64 @imp_null_check_load_shift_add_addr(ptr %x, i64 %r) {116  entry:117   %c = icmp eq ptr %x, null118   br i1 %c, label %is_null, label %not_null, !make.implicit !0119 120  is_null:121   ret i64 42122 123  not_null:124   %y = ptrtoint ptr %x to i64125   %shry = shl i64 %y, 6126   %shry.add = add i64 %shry, %r127   %y.ptr = inttoptr i64 %shry.add to ptr128   %x.loc = getelementptr i64, ptr %y.ptr, i64 1129   %t = load i64, ptr %x.loc130   ret i64 %t131}132 133; the memory op is not within faulting page.134define i64 @imp_null_check_load_addr_outside_faulting_page(ptr %x) {135  entry:136   %c = icmp eq ptr %x, null137   br i1 %c, label %is_null, label %not_null, !make.implicit !0138 139  is_null:140   ret i64 42141 142  not_null:143   %y = ptrtoint ptr %x to i64144   %shry = shl i64 %y, 3145   %shry.add = add i64 %shry, 68719472640146   %y.ptr = inttoptr i64 %shry.add to ptr147   %x.loc = getelementptr i64, ptr %y.ptr, i64 1148   %t = load i64, ptr %x.loc149   ret i64 %t150}151 152!0 = !{}153