1 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
3 declare ptr @malloc(i64)
4 declare void @free(ptr)
5 declare void @usePointer(ptr)
6 declare void @usePointer2(ptr)
8 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
9 declare i64 @llvm.coro.size.i64()
10 declare ptr @llvm.coro.begin(token, ptr writeonly)
11 declare i8 @llvm.coro.suspend(token, i1)
12 declare i1 @llvm.coro.end(ptr, i1, token)
13 declare ptr @llvm.coro.free(token, ptr nocapture readonly)
14 declare token @llvm.coro.save(ptr)
16 define void @foo() presplitcoroutine {
24 %coro.id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
25 %coro.size = call i64 @llvm.coro.size.i64()
26 %coro.alloc = call ptr @malloc(i64 %coro.size)
27 %coro.state = call ptr @llvm.coro.begin(token %coro.id, ptr %coro.alloc)
28 %coro.save = call token @llvm.coro.save(ptr %coro.state)
29 %call.suspend = call i8 @llvm.coro.suspend(token %coro.save, i1 false)
30 switch i8 %call.suspend, label %suspend [
35 wakeup: ; preds = %entry
36 call void @usePointer(ptr %a0)
37 call void @usePointer(ptr %a1)
38 call void @usePointer(ptr %a2)
39 call void @usePointer(ptr %a3)
40 call void @usePointer(ptr %a4)
41 call void @usePointer2(ptr %a5)
44 suspend: ; preds = %cleanup, %entry
45 %unused = call i1 @llvm.coro.end(ptr %coro.state, i1 false, token none)
48 cleanup: ; preds = %wakeup, %entry
49 %coro.memFree = call ptr @llvm.coro.free(token %coro.id, ptr %coro.state)
50 call void @free(ptr %coro.memFree)
54 ; CHECK: %foo.Frame = type { ptr, ptr, i32, i16, i1 }
56 ; CHECK-LABEL: @foo.resume(
57 ; CHECK-NEXT: entry.resume:
58 ; CHECK-NEXT: [[A1_RELOAD_ADDR:%.*]] = getelementptr inbounds [[FOO_FRAME:%foo.Frame]], ptr [[FRAMEPTR:%.*]], i32 0, i32 2
59 ; CHECK-NEXT: [[A4_RELOAD_ADDR:%.*]] = getelementptr inbounds [[FOO_FRAME]], ptr [[FRAMEPTR]], i32 0, i32 3
60 ; CHECK-NEXT: call void @usePointer(ptr [[FRAMEPTR]])
61 ; CHECK-NEXT: call void @usePointer(ptr [[A1_RELOAD_ADDR]])
62 ; CHECK-NEXT: call void @usePointer(ptr [[FRAMEPTR]])
63 ; CHECK-NEXT: call void @usePointer(ptr [[FRAMEPTR]])
64 ; CHECK-NEXT: call void @usePointer(ptr [[A4_RELOAD_ADDR]])
65 ; CHECK-NEXT: call void @usePointer2(ptr [[FRAMEPTR]])
66 ; CHECK-NEXT: call void @free(ptr [[FRAMEPTR]])
67 ; CHECK-NEXT: ret void