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 4 5declare void @fakeresume1(ptr) 6declare void @may_throw(ptr) 7declare void @print() 8 9define void @f(i1 %cond) #0 personality i32 3 { 10entry: 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) 14 15 %save = call token @llvm.coro.save(ptr null) 16 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 20 i8 1, label %coro.end 21 ] 22await.ready: 23 call fastcc void @fakeresume1(ptr align 8 null) 24 invoke void @may_throw(ptr null) 25 to label %ready unwind label %lpad 26 27ready: 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 32 33cleanup: 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 37 38lpad: 39 %lpval = landingpad { ptr, i32 } 40 cleanup 41 42 %need.resume = call i1 @llvm.coro.end(ptr null, i1 true, token none) 43 resume { ptr, i32 } %lpval 44 45coro.free: 46 call void @delete(ptr nonnull %free.handle) #2 47 br label %coro.end 48 49coro.end: 50 call i1 @llvm.coro.end(ptr null, i1 false, token none) 51 ret void 52} 53 54; CHECK-LABEL: @f.resume( 55; CHECK-NOT: musttail call fastcc void @fakeresume1( 56; CHECK: } 57 58 59declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1 60declare i1 @llvm.coro.alloc(token) #2 61declare i64 @llvm.coro.size.i64() #3 62declare ptr @llvm.coro.begin(token, ptr writeonly) #2 63declare token @llvm.coro.save(ptr) #2 64declare ptr @llvm.coro.frame() #3 65declare i8 @llvm.coro.suspend(token, i1) #2 66declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1 67declare i1 @llvm.coro.end(ptr, i1, token) #2 68declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1 69declare ptr @malloc(i64) 70declare void @delete(ptr nonnull) #2 71 72attributes #0 = { presplitcoroutine } 73attributes #1 = { argmemonly nounwind readonly } 74attributes #2 = { nounwind } 75attributes #3 = { nounwind readnone } 76