67 lines · plain
1; Tests that coro-split will optimize the lifetime.start maker of each local variable,2; sink them to the places after the suspend block.3; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse,simplifycfg' -S | FileCheck %s4 5%"struct.std::coroutine_handle" = type { ptr }6%"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }7%"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }8 9declare ptr @malloc(i64)10declare void @print(i32)11declare void @consume.i8(i8)12 13define void @a() presplitcoroutine {14entry:15 %ref.tmp7 = alloca %"struct.lean_future<int>::Awaiter", align 816 %testval = alloca i817 ; lifetime of %testval starts here, but not used until await.ready.18 call void @llvm.lifetime.start.p0(ptr %testval)19 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)20 %alloc = call ptr @malloc(i64 16) #321 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)22 23 %save = call token @llvm.coro.save(ptr null)24 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)25 switch i8 %suspend, label %exit [26 i8 0, label %await.ready27 i8 1, label %exit28 ]29await.ready:30 %StrayCoroSave = call token @llvm.coro.save(ptr null)31 %val = load i32, ptr %ref.tmp732 %test = load i8, ptr %testval33 call void @consume.i8(i8 %test)34 call void @llvm.lifetime.end.p0(ptr %testval)35 call void @print(i32 %val)36 br label %exit37exit:38 call void @llvm.coro.end(ptr null, i1 false, token none)39 ret void40}41 42; CHECK-LABEL: @a.resume(43; CHECK: %testval = alloca i8, align 144; CHECK: call void @llvm.lifetime.start.p0(ptr %testval)45; CHECK-NEXT: %val = load i32, ptr %ref.tmp746; CHECK-NEXT: %test = load i8, ptr %testval47; CHECK-NEXT: call void @consume.i8(i8 %test)48; CHECK-NEXT: call void @llvm.lifetime.end.p0(ptr %testval)49; CHECK-NEXT: call void @print(i32 %val)50; CHECK-NEXT: ret void51 52 53declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)54declare i1 @llvm.coro.alloc(token) #355declare noalias nonnull ptr @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr56declare i64 @llvm.coro.size.i64() #557declare ptr @llvm.coro.begin(token, ptr writeonly) #358declare void @"\01?puts@@YAXZZ"(...)59declare token @llvm.coro.save(ptr) #360declare ptr @llvm.coro.frame() #561declare i8 @llvm.coro.suspend(token, i1) #362declare void @"\01??3@YAXPEAX@Z"(ptr) local_unnamed_addr #1063declare ptr @llvm.coro.free(token, ptr nocapture readonly) #264declare void @llvm.coro.end(ptr, i1, token) #365declare void @llvm.lifetime.start.p0(ptr nocapture) #466declare void @llvm.lifetime.end.p0(ptr nocapture) #467