1; RUN: opt < %s -O0 -S | FileCheck --check-prefixes=CHECK %s 2 3target datalayout = "p:64:64:64" 4 5%async.task = type { i64 } 6%async.actor = type { i64 } 7%async.fp = type <{ i32, i32 }> 8 9%async.ctxt = type { ptr, ptr } 10 11; The async callee. 12@my_other_async_function_fp = external global <{ i32, i32 }> 13declare void @my_other_async_function(ptr %async.ctxt) 14 15@my_async_function_fp = constant <{ i32, i32 }> 16 <{ i32 trunc ( ; Relative pointer to async function 17 i64 sub ( 18 i64 ptrtoint (ptr @my_async_function to i64), 19 i64 ptrtoint (ptr getelementptr inbounds (<{ i32, i32 }>, ptr @my_async_function_fp, i32 0, i32 1) to i64) 20 ) 21 to i32), 22 i32 128 ; Initial async context size without space for frame 23}> 24 25define swiftcc void @my_other_async_function_fp.apply(ptr %fnPtr, ptr %async.ctxt) { 26 tail call swiftcc void %fnPtr(ptr %async.ctxt) 27 ret void 28} 29 30declare void @escape(ptr) 31declare void @store_resume(ptr) 32define ptr @resume_context_projection(ptr %ctxt) { 33entry: 34 %resume_ctxt = load ptr, ptr %ctxt, align 8 35 ret ptr %resume_ctxt 36} 37 38; The address of alloca escapes but the analysis based on lifetimes fails to see 39; that it can't localize this alloca. 40; CHECK: define swiftcc void @my_async_function(ptr swiftasync %async.ctxt) { 41; CHECK: entry: 42; CHECK-NOT: ret 43; CHECK-NOT: [[ESCAPED_ADDR:%.*]] = alloca i64, align 8 44; CHECK: ret 45define swiftcc void @my_async_function(ptr swiftasync %async.ctxt) { 46entry: 47 %escaped_addr = alloca i64 48 49 %id = call token @llvm.coro.id.async(i32 128, i32 16, i32 0, 50 ptr @my_async_function_fp) 51 %hdl = call ptr @llvm.coro.begin(token %id, ptr null) 52 call void @llvm.lifetime.start.p0(i64 4, ptr %escaped_addr) 53 call void @escape(ptr %escaped_addr) 54 br label %callblock 55 56 57callblock: 58 59 %callee_context = call ptr @context_alloc() 60 61 %resume.func_ptr = call ptr @llvm.coro.async.resume() 62 call void @store_resume(ptr %resume.func_ptr) 63 %res = call {ptr, ptr, ptr} (i32, ptr, ptr, ...) @llvm.coro.suspend.async(i32 0, 64 ptr %resume.func_ptr, 65 ptr @resume_context_projection, 66 ptr @my_other_async_function_fp.apply, 67 ptr @asyncSuspend, ptr %callee_context) 68 br label %callblock 69} 70 71declare { ptr, ptr, ptr, ptr } @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s(i32, ptr, ptr, ...) 72declare ptr @llvm.coro.prepare.async(ptr) 73declare token @llvm.coro.id.async(i32, i32, i32, ptr) 74declare ptr @llvm.coro.begin(token, ptr) 75declare i1 @llvm.coro.end.async(ptr, i1, ...) 76declare i1 @llvm.coro.end(ptr, i1, token) 77declare {ptr, ptr, ptr} @llvm.coro.suspend.async(i32, ptr, ptr, ...) 78declare ptr @context_alloc() 79declare void @llvm.coro.async.context.dealloc(ptr) 80declare swiftcc void @asyncSuspend(ptr) 81declare ptr @llvm.coro.async.resume() 82declare void @llvm.coro.async.size.replace(ptr, ptr) 83declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0 84declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0 85attributes #0 = { argmemonly nofree nosync nounwind willreturn } 86