1 ; Tests that coro-split won't fall in infinite loop when simplify the terminators leading to ret.
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
3 ; RUN: opt < %s -passes='pgo-instr-gen,cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
5 declare void @fakeresume1(ptr)
6 declare void @may_throw(ptr)
9 define void @f(i1 %cond) #0 personality i32 3 {
11 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
12 %alloc = call ptr @malloc(i64 16) #3
13 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
15 %save = call token @llvm.coro.save(ptr null)
17 %init_suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
18 switch i8 %init_suspend, label %coro.end [
19 i8 0, label %await.ready
23 call fastcc void @fakeresume1(ptr align 8 null)
24 invoke void @may_throw(ptr null)
25 to label %ready unwind label %lpad
28 %save2 = call token @llvm.coro.save(ptr null)
29 %suspend = call i8 @llvm.coro.suspend(token %save2, i1 true)
30 %switch = icmp ult i8 %suspend, 2
31 br i1 %switch, label %cleanup, label %coro.end
34 %free.handle = call ptr @llvm.coro.free(token %id, ptr %vFrame)
35 %.not = icmp eq ptr %free.handle, null
36 br i1 %.not, label %coro.end, label %coro.free
39 %lpval = landingpad { ptr, i32 }
42 %need.resume = call i1 @llvm.coro.end(ptr null, i1 true, token none)
43 resume { ptr, i32 } %lpval
46 call void @delete(ptr nonnull %free.handle) #2
50 call i1 @llvm.coro.end(ptr null, i1 false, token none)
54 ; CHECK-LABEL: @f.resume(
55 ; CHECK-NOT: musttail call fastcc void @fakeresume1(
59 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
60 declare i1 @llvm.coro.alloc(token) #2
61 declare i64 @llvm.coro.size.i64() #3
62 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
63 declare token @llvm.coro.save(ptr) #2
64 declare ptr @llvm.coro.frame() #3
65 declare i8 @llvm.coro.suspend(token, i1) #2
66 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
67 declare i1 @llvm.coro.end(ptr, i1, token) #2
68 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
69 declare ptr @malloc(i64)
70 declare void @delete(ptr nonnull) #2
72 attributes #0 = { presplitcoroutine }
73 attributes #1 = { argmemonly nounwind readonly }
74 attributes #2 = { nounwind }
75 attributes #3 = { nounwind readnone }