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 %s
5 %"struct.std::coroutine_handle" = type { i8* }
6 %"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }
7 %"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }
9 declare i8* @malloc(i64)
10 declare void @print(i32)
11 declare void @consume.i8(i8)
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.p0i8(i64 1, i8* %testval)
19 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
20 %alloc = call i8* @malloc(i64 16) #3
21 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
23 %save = call token @llvm.coro.save(i8* null)
24 %Result.i19 = getelementptr inbounds %"struct.lean_future<int>::Awaiter", %"struct.lean_future<int>::Awaiter"* %ref.tmp7, i64 0, i32 0
25 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
26 switch i8 %suspend, label %exit [
27 i8 0, label %await.ready
31 %StrayCoroSave = call token @llvm.coro.save(i8* null)
32 %val = load i32, i32* %Result.i19
33 %test = load i8, i8* %testval
34 call void @consume.i8(i8 %test)
35 call void @llvm.lifetime.end.p0i8(i64 1, i8* %testval)
36 call void @print(i32 %val)
39 call i1 @llvm.coro.end(i8* null, i1 false)
43 ; CHECK-LABEL: @a.resume(
44 ; CHECK: %testval = alloca i8, align 1
45 ; CHECK-NEXT: getelementptr inbounds %a.Frame
46 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* %testval)
47 ; CHECK-NEXT: getelementptr inbounds %"struct.lean_future<int>::Awaiter"
48 ; CHECK-NEXT: %val = load i32, i32* %Result
49 ; CHECK-NEXT: %test = load i8, i8* %testval
50 ; CHECK-NEXT: call void @consume.i8(i8 %test)
51 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* %testval)
52 ; CHECK-NEXT: call void @print(i32 %val)
53 ; CHECK-NEXT: ret void
56 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
57 declare i1 @llvm.coro.alloc(token) #3
58 declare noalias nonnull i8* @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr
59 declare i64 @llvm.coro.size.i64() #5
60 declare i8* @llvm.coro.begin(token, i8* writeonly) #3
61 declare void @"\01?puts@@YAXZZ"(...)
62 declare token @llvm.coro.save(i8*) #3
63 declare i8* @llvm.coro.frame() #5
64 declare i8 @llvm.coro.suspend(token, i1) #3
65 declare void @"\01??3@YAXPEAX@Z"(i8*) local_unnamed_addr #10
66 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #2
67 declare i1 @llvm.coro.end(i8*, i1) #3
68 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #4
69 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #4