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' -S | FileCheck %s
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" }
10 declare ptr @malloc(i64)
11 declare void @print(i32)
13 define void @a() presplitcoroutine {
15 %ref.tmp7 = alloca %"struct.lean_future<int>::Awaiter", align 8
17 ; lifetime of %testval starts here, but not used until await.ready.
18 call void @llvm.lifetime.start.p0(i64 4, ptr %testval)
19 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
20 %alloc = call ptr @malloc(i64 16) #3
21 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
22 %testcond = call i1 @getcond()
23 br i1 %testcond, label %if.suspend, label %else.direct
26 %save = call token @llvm.coro.save(ptr null)
27 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
28 switch i8 %suspend, label %exit [
29 i8 0, label %await.ready
37 %StrayCoroSave = call token @llvm.coro.save(ptr null)
38 %val = load i32, ptr %ref.tmp7
39 %test = load i32, ptr %testval
40 call void @print(i32 %test)
41 call void @print(i32 %val)
45 %test1 = load i32, ptr %testval
46 call void @print(i32 %test1)
47 call void @llvm.lifetime.end.p0(i64 4, ptr %testval)
51 call i1 @llvm.coro.end(ptr null, i1 false, token none)
55 ; CHECK-LABEL: @a.resume(
56 ; CHECK: %[[VAL:testval.+]] = getelementptr inbounds %a.Frame
57 ; CHECK-NOT: call void @llvm.lifetime.start.p0(i64 4, ptr %{{.*}})
58 ; CHECK: %test = load i32, ptr %[[VAL]]
60 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
61 declare i1 @llvm.coro.alloc(token) #3
62 declare noalias nonnull ptr @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr
63 declare i64 @llvm.coro.size.i64() #5
64 declare ptr @llvm.coro.begin(token, ptr writeonly) #3
65 declare void @"\01?puts@@YAXZZ"(...)
66 declare token @llvm.coro.save(ptr) #3
67 declare ptr @llvm.coro.frame() #5
68 declare i8 @llvm.coro.suspend(token, i1) #3
69 declare void @"\01??3@YAXPEAX@Z"(ptr) local_unnamed_addr #10
70 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
71 declare i1 @llvm.coro.end(ptr, i1, token) #3
72 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #4
73 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #4