1*9880d681SAndroid Build Coastguard Worker; RUN: opt -inline -S < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.start(i64, i8*) 5*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.end(i64, i8*) 6*9880d681SAndroid Build Coastguard Worker 7*9880d681SAndroid Build Coastguard Workerdefine void @helper_both_markers() { 8*9880d681SAndroid Build Coastguard Worker %a = alloca i8 9*9880d681SAndroid Build Coastguard Worker ; Size in llvm.lifetime.start / llvm.lifetime.end differs from 10*9880d681SAndroid Build Coastguard Worker ; allocation size. We should use the former. 11*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.start(i64 2, i8* %a) 12*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.end(i64 2, i8* %a) 13*9880d681SAndroid Build Coastguard Worker ret void 14*9880d681SAndroid Build Coastguard Worker} 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Workerdefine void @test_both_markers() { 17*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_both_markers( 18*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.start(i64 2 19*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: llvm.lifetime.end(i64 2 20*9880d681SAndroid Build Coastguard Worker call void @helper_both_markers() 21*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: llvm.lifetime.start(i64 2 22*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: llvm.lifetime.end(i64 2 23*9880d681SAndroid Build Coastguard Worker call void @helper_both_markers() 24*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void 25*9880d681SAndroid Build Coastguard Worker ret void 26*9880d681SAndroid Build Coastguard Worker} 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker;; Without this, the inliner will simplify out @test_no_marker before adding 29*9880d681SAndroid Build Coastguard Worker;; any lifetime markers. 30*9880d681SAndroid Build Coastguard Workerdeclare void @use(i8* %a) 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Workerdefine void @helper_no_markers() { 33*9880d681SAndroid Build Coastguard Worker %a = alloca i8 ; Allocation size is 1 byte. 34*9880d681SAndroid Build Coastguard Worker call void @use(i8* %a) 35*9880d681SAndroid Build Coastguard Worker ret void 36*9880d681SAndroid Build Coastguard Worker} 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker;; We can't use CHECK-NEXT because there's an extra call void @use in between. 39*9880d681SAndroid Build Coastguard Worker;; Instead, we use CHECK-NOT to verify that there are no other lifetime calls. 40*9880d681SAndroid Build Coastguard Workerdefine void @test_no_marker() { 41*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_no_marker( 42*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 43*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.start(i64 1 44*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 45*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.end(i64 1 46*9880d681SAndroid Build Coastguard Worker call void @helper_no_markers() 47*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 48*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.start(i64 1 49*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 50*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.end(i64 1 51*9880d681SAndroid Build Coastguard Worker call void @helper_no_markers() 52*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 53*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 54*9880d681SAndroid Build Coastguard Worker ret void 55*9880d681SAndroid Build Coastguard Worker} 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Workerdefine void @helper_two_casts() { 58*9880d681SAndroid Build Coastguard Worker %a = alloca i32 59*9880d681SAndroid Build Coastguard Worker %b = bitcast i32* %a to i8* 60*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.start(i64 4, i8* %b) 61*9880d681SAndroid Build Coastguard Worker %c = bitcast i32* %a to i8* 62*9880d681SAndroid Build Coastguard Worker call void @llvm.lifetime.end(i64 4, i8* %c) 63*9880d681SAndroid Build Coastguard Worker ret void 64*9880d681SAndroid Build Coastguard Worker} 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Workerdefine void @test_two_casts() { 67*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_two_casts( 68*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 69*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.start(i64 4 70*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 71*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.end(i64 4 72*9880d681SAndroid Build Coastguard Worker call void @helper_two_casts() 73*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 74*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.start(i64 4 75*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 76*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.end(i64 4 77*9880d681SAndroid Build Coastguard Worker call void @helper_two_casts() 78*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 79*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 80*9880d681SAndroid Build Coastguard Worker ret void 81*9880d681SAndroid Build Coastguard Worker} 82*9880d681SAndroid Build Coastguard Worker 83*9880d681SAndroid Build Coastguard Workerdefine void @helper_arrays_alloca() { 84*9880d681SAndroid Build Coastguard Worker %a = alloca [10 x i32], align 16 85*9880d681SAndroid Build Coastguard Worker %1 = bitcast [10 x i32]* %a to i8* 86*9880d681SAndroid Build Coastguard Worker call void @use(i8* %1) 87*9880d681SAndroid Build Coastguard Worker ret void 88*9880d681SAndroid Build Coastguard Worker} 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Workerdefine void @test_arrays_alloca() { 91*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test_arrays_alloca( 92*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 93*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.start(i64 40, 94*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 95*9880d681SAndroid Build Coastguard Worker; CHECK: llvm.lifetime.end(i64 40, 96*9880d681SAndroid Build Coastguard Worker call void @helper_arrays_alloca() 97*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: lifetime 98*9880d681SAndroid Build Coastguard Worker; CHECK: ret void 99*9880d681SAndroid Build Coastguard Worker ret void 100*9880d681SAndroid Build Coastguard Worker} 101