1; RUN: opt -inline -S < %s | FileCheck %s 2; RUN: opt -passes='cgscc(inline)' -S < %s | FileCheck %s 3target 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" 4 5declare void @llvm.lifetime.start.p0i8(i64, i8*) 6declare void @llvm.lifetime.end.p0i8(i64, i8*) 7 8define void @helper_both_markers() { 9 %a = alloca i8 10 ; Size in llvm.lifetime.start / llvm.lifetime.end differs from 11 ; allocation size. We should use the former. 12 call void @llvm.lifetime.start.p0i8(i64 2, i8* %a) 13 call void @llvm.lifetime.end.p0i8(i64 2, i8* %a) 14 ret void 15} 16 17define void @test_both_markers() { 18; CHECK-LABEL: @test_both_markers( 19; CHECK: llvm.lifetime.start.p0i8(i64 2 20; CHECK-NEXT: llvm.lifetime.end.p0i8(i64 2 21 call void @helper_both_markers() 22; CHECK-NEXT: llvm.lifetime.start.p0i8(i64 2 23; CHECK-NEXT: llvm.lifetime.end.p0i8(i64 2 24 call void @helper_both_markers() 25; CHECK-NEXT: ret void 26 ret void 27} 28 29;; Without this, the inliner will simplify out @test_no_marker before adding 30;; any lifetime markers. 31declare void @use(i8* %a) 32 33define void @helper_no_markers() { 34 %a = alloca i8 ; Allocation size is 1 byte. 35 call void @use(i8* %a) 36 ret void 37} 38 39;; We can't use CHECK-NEXT because there's an extra call void @use in between. 40;; Instead, we use CHECK-NOT to verify that there are no other lifetime calls. 41define void @test_no_marker() { 42; CHECK-LABEL: @test_no_marker( 43; CHECK-NOT: lifetime 44; CHECK: llvm.lifetime.start.p0i8(i64 1 45; CHECK-NOT: lifetime 46; CHECK: llvm.lifetime.end.p0i8(i64 1 47 call void @helper_no_markers() 48; CHECK-NOT: lifetime 49; CHECK: llvm.lifetime.start.p0i8(i64 1 50; CHECK-NOT: lifetime 51; CHECK: llvm.lifetime.end.p0i8(i64 1 52 call void @helper_no_markers() 53; CHECK-NOT: lifetime 54; CHECK: ret void 55 ret void 56} 57 58define void @helper_two_casts() { 59 %a = alloca i32 60 %b = bitcast i32* %a to i8* 61 call void @llvm.lifetime.start.p0i8(i64 4, i8* %b) 62 %c = bitcast i32* %a to i8* 63 call void @llvm.lifetime.end.p0i8(i64 4, i8* %c) 64 ret void 65} 66 67define void @test_two_casts() { 68; CHECK-LABEL: @test_two_casts( 69; CHECK-NOT: lifetime 70; CHECK: llvm.lifetime.start.p0i8(i64 4 71; CHECK-NOT: lifetime 72; CHECK: llvm.lifetime.end.p0i8(i64 4 73 call void @helper_two_casts() 74; CHECK-NOT: lifetime 75; CHECK: llvm.lifetime.start.p0i8(i64 4 76; CHECK-NOT: lifetime 77; CHECK: llvm.lifetime.end.p0i8(i64 4 78 call void @helper_two_casts() 79; CHECK-NOT: lifetime 80; CHECK: ret void 81 ret void 82} 83 84define void @helper_arrays_alloca() { 85 %a = alloca [10 x i32], align 16 86 %1 = bitcast [10 x i32]* %a to i8* 87 call void @use(i8* %1) 88 ret void 89} 90 91define void @test_arrays_alloca() { 92; CHECK-LABEL: @test_arrays_alloca( 93; CHECK-NOT: lifetime 94; CHECK: llvm.lifetime.start.p0i8(i64 40, 95; CHECK-NOT: lifetime 96; CHECK: llvm.lifetime.end.p0i8(i64 40, 97 call void @helper_arrays_alloca() 98; CHECK-NOT: lifetime 99; CHECK: ret void 100 ret void 101} 102 103%swift.error = type opaque 104 105define void @helper_swifterror_alloca() { 106entry: 107 %swifterror = alloca swifterror %swift.error*, align 8 108 store %swift.error* null, %swift.error** %swifterror, align 8 109 ret void 110} 111 112define void @test_swifterror_alloca() { 113; CHECK-LABEL: @test_swifterror_alloca( 114; CHECK-NOT: lifetime 115 call void @helper_swifterror_alloca() 116; CHECK: ret void 117 ret void 118} 119