1 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
2 %promise_type = type { i8 }
3 %struct.A = type <{ i64, i64, i32, [4 x i8] }>
5 ; Function Attrs: noinline ssp uwtable mustprogress
6 define ptr @foo(ptr nocapture readonly byval(%struct.A) align 8 %a1) #0 {
8 %__promise = alloca %promise_type, align 1
9 %a2 = alloca %struct.A, align 8
10 %0 = call token @llvm.coro.id(i32 16, ptr nonnull %__promise, ptr @foo, ptr null)
11 %1 = call i1 @llvm.coro.alloc(token %0)
12 br i1 %1, label %coro.alloc, label %coro.init
14 coro.alloc: ; preds = %entry
15 %2 = call i64 @llvm.coro.size.i64()
16 %call = call noalias nonnull ptr @_Znwm(i64 %2) #9
19 coro.init: ; preds = %coro.alloc, %entry
20 %3 = phi ptr [ null, %entry ], [ %call, %coro.alloc ]
21 %4 = call ptr @llvm.coro.begin(token %0, ptr %3) #10
22 call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %__promise) #2
23 %call2 = call ptr @_ZN4task12promise_type17get_return_objectEv(ptr nonnull dereferenceable(1) %__promise)
24 call void @initial_suspend(ptr nonnull dereferenceable(1) %__promise)
25 %5 = call token @llvm.coro.save(ptr null)
26 call fastcc void @_ZNSt12experimental13coroutines_v116coroutine_handleIN4task12promise_typeEE12from_addressEPv(ptr %4) #2
27 %6 = call i8 @llvm.coro.suspend(token %5, i1 false)
28 switch i8 %6, label %coro.ret [
29 i8 0, label %init.ready
30 i8 1, label %cleanup33
33 init.ready: ; preds = %coro.init
34 call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %a2) #2
35 call void @llvm.memcpy.p0.p0.i64(ptr align 8 %a2, ptr align 8 %a1, i64 24, i1 false)
36 call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %a2) #2
37 call void @_ZN4task12promise_type13final_suspendEv(ptr nonnull dereferenceable(1) %__promise) #2
38 %7 = call token @llvm.coro.save(ptr null)
39 call fastcc void @_ZNSt12experimental13coroutines_v116coroutine_handleIN4task12promise_typeEE12from_addressEPv(ptr %4) #2
40 %8 = call i8 @llvm.coro.suspend(token %7, i1 true) #10
41 %switch = icmp ult i8 %8, 2
42 br i1 %switch, label %cleanup33, label %coro.ret
44 cleanup33: ; preds = %init.ready, %coro.init
45 call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %__promise) #2
46 %9 = call ptr @llvm.coro.free(token %0, ptr %4)
47 %.not = icmp eq ptr %9, null
48 br i1 %.not, label %coro.ret, label %coro.free
50 coro.free: ; preds = %cleanup33
51 call void @_ZdlPv(ptr nonnull %9) #2
54 coro.ret: ; preds = %coro.free, %cleanup33, %init.ready, %coro.init
55 %10 = call i1 @llvm.coro.end(ptr null, i1 false, token none) #10
59 ; check that the frame contains the entire struct, instead of just the struct pointer
60 ; CHECK: %foo.Frame = type { ptr, ptr, %promise_type, %struct.A, i1 }
62 ; Function Attrs: argmemonly nounwind readonly
63 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
65 ; Function Attrs: nounwind
66 declare i1 @llvm.coro.alloc(token) #2
68 ; Function Attrs: nobuiltin nofree allocsize(0)
69 declare nonnull ptr @_Znwm(i64) local_unnamed_addr #3
71 ; Function Attrs: nounwind readnone
72 declare i64 @llvm.coro.size.i64() #4
74 ; Function Attrs: nounwind
75 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
77 ; Function Attrs: argmemonly nofree nosync nounwind willreturn
78 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #5
80 ; Function Attrs: argmemonly nofree nounwind willreturn
81 declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6
83 ; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
84 declare ptr @_ZN4task12promise_type17get_return_objectEv(ptr nonnull dereferenceable(1)) local_unnamed_addr #7 align 2
86 ; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
87 declare void @initial_suspend(ptr nonnull dereferenceable(1)) local_unnamed_addr #7 align 2
89 ; Function Attrs: nounwind
90 declare token @llvm.coro.save(ptr) #2
92 ; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
93 declare hidden fastcc void @_ZNSt12experimental13coroutines_v116coroutine_handleIN4task12promise_typeEE12from_addressEPv(ptr) unnamed_addr #7 align 2
95 ; Function Attrs: argmemonly nofree nosync nounwind willreturn
96 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #5
98 ; Function Attrs: nounwind
99 declare i8 @llvm.coro.suspend(token, i1) #2
101 ; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
102 declare void @_ZN4task12promise_type13final_suspendEv(ptr nonnull dereferenceable(1)) local_unnamed_addr #7 align 2
104 ; Function Attrs: nounwind
105 declare i1 @llvm.coro.end(ptr, i1, token) #2
107 ; Function Attrs: nobuiltin nounwind
108 declare void @_ZdlPv(ptr) local_unnamed_addr #8
110 ; Function Attrs: argmemonly nounwind readonly
111 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
113 attributes #0 = { noinline ssp uwtable mustprogress presplitcoroutine "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
114 attributes #1 = { argmemonly nounwind readonly }
115 attributes #2 = { nounwind }
116 attributes #3 = { nobuiltin nofree allocsize(0) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
117 attributes #4 = { nounwind readnone }
118 attributes #5 = { argmemonly nofree nosync nounwind willreturn }
119 attributes #6 = { argmemonly nofree nounwind willreturn }
120 attributes #7 = { noinline nounwind ssp uwtable willreturn mustprogress "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
121 attributes #8 = { nobuiltin nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
122 attributes #9 = { allocsize(0) }
123 attributes #10 = { noduplicate }