1 ; RUN: opt < %s -enable-coroutines -O2 -S | FileCheck %s
3 define i8* @f(i8* %buffer, i32 %n) {
5 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i32, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
6 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
10 %n.val = phi i32 [ %n, %entry ], [ %sum, %resume ]
11 %values = call { i32, i1 } (...) @llvm.coro.suspend.retcon.sl_i32i1s()
12 %finished = extractvalue { i32, i1 } %values, 1
13 br i1 %finished, label %cleanup, label %resume
16 %input = extractvalue { i32, i1 } %values, 0
17 %sum = add i32 %n.val, %input
21 call void @print(i32 %n.val)
22 call i1 @llvm.coro.end(i8* %hdl, i1 0)
26 ; CHECK-LABEL: define i8* @f(i8* %buffer, i32 %n)
28 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %buffer to i32*
29 ; CHECK-NEXT: store i32 %n, i32* [[T0]], align 4
30 ; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i32, i1)* @f.resume.0 to i8*)
33 ; CHECK-LABEL: define internal i8* @f.resume.0(i8* noalias nonnull %0, i32 %1, i1 zeroext %2)
35 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %0 to i32*
36 ; CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[T0]], align 4
37 ; CHECK-NEXT: br i1 %2,
39 ; CHECK-NEXT: %sum = add i32 [[T1]], %1
40 ; CHECK-NEXT: store i32 %sum, i32* [[T0]], align 4
41 ; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i32, i1)* @f.resume.0 to i8*)
43 ; CHECK-NEXT: call void @print(i32 [[T1]])
44 ; CHECK-NEXT: ret i8* null
49 %0 = alloca [8 x i8], align 4
50 %buffer = bitcast [8 x i8]* %0 to i8*
51 %prepare = call i8* @llvm.coro.prepare.retcon(i8* bitcast (i8* (i8*, i32)* @f to i8*))
52 %f = bitcast i8* %prepare to i8* (i8*, i32)*
53 %cont0 = call i8* %f(i8* %buffer, i32 1)
54 %cont0.cast = bitcast i8* %cont0 to i8* (i8*, i32, i1)*
55 %cont1 = call i8* %cont0.cast(i8* %buffer, i32 2, i1 zeroext false)
56 %cont1.cast = bitcast i8* %cont1 to i8* (i8*, i32, i1)*
57 %cont2 = call i8* %cont1.cast(i8* %buffer, i32 4, i1 zeroext false)
58 %cont2.cast = bitcast i8* %cont2 to i8* (i8*, i32, i1)*
59 call i8* %cont2.cast(i8* %buffer, i32 100, i1 zeroext true)
63 ; Unfortunately, we don't seem to fully optimize this right now due
64 ; to some sort of phase-ordering thing.
65 ; CHECK-LABEL: define i32 @main
67 ; CHECK: [[BUFFER:%.*]] = alloca [8 x i8], align 4
68 ; CHECK: [[SLOT:%.*]] = bitcast [8 x i8]* [[BUFFER]] to i32*
69 ; CHECK-NEXT: store i32 7, i32* [[SLOT]], align 4
70 ; CHECK-NEXT: call void @print(i32 7)
71 ; CHECK-NEXT: ret i32 0
73 declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*)
74 declare i8* @llvm.coro.begin(token, i8*)
75 declare { i32, i1 } @llvm.coro.suspend.retcon.sl_i32i1s(...)
76 declare i1 @llvm.coro.end(i8*, i1)
77 declare i8* @llvm.coro.prepare.retcon(i8*)
79 declare i8* @prototype(i8*, i32, i1 zeroext)
81 declare noalias i8* @allocate(i32 %size)
82 declare void @deallocate(i8* %ptr)
84 declare void @print(i32)