1 ; RUN: opt < %s -instcombine -S | FileCheck %s 2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" 3 4 ; Uses InstCombine with DataLayout to propagate dereferenceable 5 ; attribute via gc.relocate: if the derived ptr is dereferenceable(N), 6 ; then the return attribute of gc.relocate is dereferenceable(N). 7 8 declare zeroext i1 @return_i1() 9 declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...) 10 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) 11 12 define i32 @explicit_nonnull(i32 addrspace(1)* nonnull %dparam) gc "statepoint-example" { 13 ; Checks that a nonnull pointer 14 ; CHECK-LABEL: @explicit_nonnull 15 ; CHECK: ret i32 1 16 entry: 17 %load = load i32, i32 addrspace(1)* %dparam 18 %tok = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam) 19 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok, i32 7, i32 7) 20 %cmp = icmp eq i32 addrspace(1)* %relocate, null 21 %ret_val = select i1 %cmp, i32 0, i32 1 22 ret i32 %ret_val 23 } 24 25 define i32 @implicit_nonnull(i32 addrspace(1)* %dparam) gc "statepoint-example" { 26 ; Checks that a nonnull pointer 27 ; CHECK-LABEL: @implicit_nonnull 28 ; CHECK: ret i32 1 29 entry: 30 %cond = icmp eq i32 addrspace(1)* %dparam, null 31 br i1 %cond, label %no_gc, label %gc 32 gc: 33 %load = load i32, i32 addrspace(1)* %dparam 34 %tok = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam) 35 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok, i32 7, i32 7) 36 %cmp = icmp eq i32 addrspace(1)* %relocate, null 37 %ret_val = select i1 %cmp, i32 0, i32 1 38 ret i32 %ret_val 39 no_gc: 40 unreachable 41 } 42 43 44 ; Make sure we don't crash when processing vectors 45 define <2 x i8 addrspace(1)*> @vector(<2 x i8 addrspace(1)*> %obj) gc "statepoint-example" { 46 entry: 47 ; CHECK-LABEL: @vector 48 ; CHECK: gc.statepoint 49 ; CHECK: gc.relocate 50 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0, <2 x i8 addrspace(1)*> %obj) 51 %obj.relocated = call coldcc <2 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v2p1i8(token %safepoint_token, i32 7, i32 7) ; (%obj, %obj) 52 ret <2 x i8 addrspace(1)*> %obj.relocated 53 } 54 55 declare void @do_safepoint() 56 57 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) 58 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32) 59 declare <2 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v2p1i8(token, i32, i32) 60