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 i8* @f2(i1 %val) "coroutine.presplit"="1" personality i32 4 {
7 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
8 %hdl = call i8* @llvm.coro.begin(token %id, i8* 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(i8* %hdl, i1 0)
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(i8* null, i1 true) [ "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 i8* @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 ; CHECK-NEXT: cleanupret from %tok unwind to caller
66 declare i8* @llvm.coro.free(token, i8*)
67 declare i32 @llvm.coro.size.i32()
68 declare i8 @llvm.coro.suspend(token, i1)
69 declare void @llvm.coro.resume(i8*)
70 declare void @llvm.coro.destroy(i8*)
72 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
73 declare i8* @llvm.coro.alloc(token)
74 declare i8* @llvm.coro.begin(token, i8*)
75 declare i1 @llvm.coro.end(i8*, i1)
77 declare noalias i8* @malloc(i32)
78 declare void @print(i32)
79 declare void @free(i8*)