1 ; Tests that variables in a Corotuine whose lifetime range is not overlapping each other
2 ; re-use the same slot in Coroutine frame.
3 ; RUN: opt < %s -passes='cgscc(coro-split<reuse-storage>),simplifycfg,early-cse' -S | FileCheck %s
4 %"struct.task::promise_type" = type { i8 }
5 %struct.awaitable = type { i8 }
6 %struct.big_structure = type { [500 x i8] }
7 declare i8* @malloc(i64)
8 declare void @consume(%struct.big_structure*)
9 define void @a(i1 zeroext %cond) presplitcoroutine {
11 %__promise = alloca %"struct.task::promise_type", align 1
12 %a = alloca %struct.big_structure, align 1
13 %ref.tmp7 = alloca %struct.awaitable, align 1
14 %b = alloca %struct.big_structure, align 1
15 %ref.tmp18 = alloca %struct.awaitable, align 1
16 %0 = getelementptr inbounds %"struct.task::promise_type", %"struct.task::promise_type"* %__promise, i64 0, i32 0
17 %1 = call token @llvm.coro.id(i32 16, i8* nonnull %0, i8* bitcast (void (i1)* @a to i8*), i8* null)
20 %2 = call noalias nonnull i8* @llvm.coro.begin(token %1, i8* null)
21 call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %0)
22 br i1 %cond, label %if.then, label %if.else
24 %3 = getelementptr inbounds %struct.big_structure, %struct.big_structure* %a, i64 0, i32 0, i64 0
25 call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %3)
26 call void @consume(%struct.big_structure* nonnull %a)
27 %save = call token @llvm.coro.save(i8* null)
28 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
29 switch i8 %suspend, label %coro.ret [
30 i8 0, label %await.ready
34 call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %3)
37 %4 = getelementptr inbounds %struct.big_structure, %struct.big_structure* %b, i64 0, i32 0, i64 0
38 call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %4)
39 call void @consume(%struct.big_structure* nonnull %b)
40 %save2 = call token @llvm.coro.save(i8* null)
41 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
42 switch i8 %suspend2, label %coro.ret [
43 i8 0, label %await2.ready
47 call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %4)
50 call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %3)
53 call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %4)
56 call i8* @llvm.coro.free(token %1, i8* %2)
59 call i1 @llvm.coro.end(i8* null, i1 false)
63 ; check that there is only one %struct.big_structure in the frame.
64 ; CHECK: %a.Frame = type { void (%a.Frame*)*, void (%a.Frame*)*, %"struct.task::promise_type", %struct.big_structure, i1 }
66 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
67 declare i1 @llvm.coro.alloc(token) #3
68 declare i64 @llvm.coro.size.i64() #5
69 declare i8* @llvm.coro.begin(token, i8* writeonly) #3
70 declare token @llvm.coro.save(i8*) #3
71 declare i8* @llvm.coro.frame() #5
72 declare i8 @llvm.coro.suspend(token, i1) #3
73 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #2
74 declare i1 @llvm.coro.end(i8*, i1) #3
75 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #4
76 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #4