1 ; Tests that coro-split removes cleanup code after coro.end in resume functions
2 ; and retains it in the start function.
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
5 define ptr @f2(i1 %val) presplitcoroutine personality i32 4 {
7 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
8 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
9 call void @print(i32 0)
10 br i1 %val, label %resume, label %susp
13 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
14 switch i8 %0, label %suspend [i8 0, label %resume
17 invoke void @print(i32 1) to label %suspend unwind label %lpad
20 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
21 call void @print(i32 0) ; should not be present in f.resume
25 %tok = cleanuppad within none []
26 call void @print(i32 2)
27 %unused = call i1 @llvm.coro.end(ptr null, i1 true, token none) [ "funclet"(token %tok) ]
28 cleanupret from %tok unwind label %cleanup.cont
31 %tok2 = cleanuppad within none []
32 call void @print(i32 3) ; should not be present in f.resume
33 cleanupret from %tok2 unwind to caller
36 ; Verify that start function contains both print calls the one before and after coro.end
37 ; CHECK-LABEL: define ptr @f2(
38 ; CHECK: invoke void @print(i32 1)
39 ; CHECK: to label %AfterCoroEnd unwind label %lpad
41 ; CHECK: AfterCoroEnd:
42 ; CHECK: call void @print(i32 0)
46 ; CHECK-NEXT: %tok = cleanuppad within none []
47 ; CHECK-NEXT: call void @print(i32 2)
48 ; CHECK-NEXT: call void @print(i32 3)
49 ; CHECK-NEXT: cleanupret from %tok unwind to caller
53 ; Verify that resume function does not contains both print calls appearing after coro.end
54 ; CHECK-LABEL: define internal fastcc void @f2.resume
55 ; CHECK: invoke void @print(i32 1)
56 ; CHECK: to label %CoroEnd unwind label %lpad
59 ; CHECK-NEXT: ret void
62 ; CHECK-NEXT: %tok = cleanuppad within none []
63 ; CHECK-NEXT: call void @print(i32 2)
64 ; Checks that the coroutine would be marked as done if it exits in unwinding path.
65 ; CHECK-NEXT: store ptr null, ptr %hdl, align 8
66 ; CHECK-NEXT: cleanupret from %tok unwind to caller
68 declare ptr @llvm.coro.free(token, ptr)
69 declare i32 @llvm.coro.size.i32()
70 declare i8 @llvm.coro.suspend(token, i1)
71 declare void @llvm.coro.resume(ptr)
72 declare void @llvm.coro.destroy(ptr)
74 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
75 declare ptr @llvm.coro.alloc(token)
76 declare ptr @llvm.coro.begin(token, ptr)
77 declare i1 @llvm.coro.end(ptr, i1, token)
79 declare noalias ptr @malloc(i32)
80 declare void @print(i32)
81 declare void @free(ptr)