1 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
3 declare i8* @malloc(i64)
4 declare void @free(i8*)
5 declare void @usePointer(i8*)
6 declare void @usePointer2([0 x i8]*)
8 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
9 declare i64 @llvm.coro.size.i64()
10 declare i8* @llvm.coro.begin(token, i8* writeonly)
11 declare i8 @llvm.coro.suspend(token, i1)
12 declare i1 @llvm.coro.end(i8*, i1)
13 declare i8* @llvm.coro.free(token, i8* nocapture readonly)
14 declare token @llvm.coro.save(i8*)
16 define void @foo() "coroutine.presplit"="1" {
24 %a0.cast = bitcast [0 x i8]* %a0 to i8*
25 %a1.cast = bitcast i32* %a1 to i8*
26 %a2.cast = bitcast [0 x i8]* %a2 to i8*
27 %a3.cast = bitcast [0 x i8]* %a3 to i8*
28 %a4.cast = bitcast i16* %a4 to i8*
29 %coro.id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
30 %coro.size = call i64 @llvm.coro.size.i64()
31 %coro.alloc = call i8* @malloc(i64 %coro.size)
32 %coro.state = call i8* @llvm.coro.begin(token %coro.id, i8* %coro.alloc)
33 %coro.save = call token @llvm.coro.save(i8* %coro.state)
34 %call.suspend = call i8 @llvm.coro.suspend(token %coro.save, i1 false)
35 switch i8 %call.suspend, label %suspend [
40 wakeup: ; preds = %entry
41 call void @usePointer(i8* %a0.cast)
42 call void @usePointer(i8* %a1.cast)
43 call void @usePointer(i8* %a2.cast)
44 call void @usePointer(i8* %a3.cast)
45 call void @usePointer(i8* %a4.cast)
46 call void @usePointer2([0 x i8]* %a5)
49 suspend: ; preds = %cleanup, %entry
50 %unused = call i1 @llvm.coro.end(i8* %coro.state, i1 false)
53 cleanup: ; preds = %wakeup, %entry
54 %coro.memFree = call i8* @llvm.coro.free(token %coro.id, i8* %coro.state)
55 call void @free(i8* %coro.memFree)
59 ; CHECK: %foo.Frame = type { void (%foo.Frame*)*, void (%foo.Frame*)*, i32, i16, i1 }
61 ; CHECK-LABEL: @foo.resume(
62 ; CHECK-NEXT: entry.resume:
63 ; CHECK-NEXT: [[VFRAME:%.*]] = bitcast %foo.Frame* [[FRAMEPTR:%.*]] to i8*
64 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[FOO_FRAME:%.*]], %foo.Frame* [[FRAMEPTR]], i32 0, i32 0
65 ; CHECK-NEXT: [[A0_RELOAD_ADDR:%.*]] = bitcast void (%foo.Frame*)** [[TMP0]] to [0 x i8]*
66 ; CHECK-NEXT: [[A1_RELOAD_ADDR:%.*]] = getelementptr inbounds [[FOO_FRAME]], %foo.Frame* [[FRAMEPTR]], i32 0, i32 2
67 ; CHECK-NEXT: [[A4_RELOAD_ADDR:%.*]] = getelementptr inbounds [[FOO_FRAME]], %foo.Frame* [[FRAMEPTR]], i32 0, i32 3
68 ; CHECK-NEXT: [[A4_CAST5:%.*]] = bitcast i16* [[A4_RELOAD_ADDR]] to i8*
69 ; CHECK-NEXT: [[A3_CAST4:%.*]] = bitcast [0 x i8]* [[A0_RELOAD_ADDR]] to i8*
70 ; CHECK-NEXT: [[A1_CAST2:%.*]] = bitcast i32* [[A1_RELOAD_ADDR]] to i8*
71 ; CHECK-NEXT: call void @usePointer(i8* [[A3_CAST4]])
72 ; CHECK-NEXT: call void @usePointer(i8* [[A1_CAST2]])
73 ; CHECK-NEXT: call void @usePointer(i8* [[A3_CAST4]])
74 ; CHECK-NEXT: call void @usePointer(i8* [[A3_CAST4]])
75 ; CHECK-NEXT: call void @usePointer(i8* [[A4_CAST5]])
76 ; CHECK-NEXT: call void @usePointer2([0 x i8]* [[A0_RELOAD_ADDR]])
77 ; CHECK-NEXT: call void @free(i8* [[VFRAME]])
78 ; CHECK-NEXT: ret void