1 ; Check that we would take care of the value written to promise before @llvm.coro.begin.
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4 %"class.task::promise_type" = type { [64 x i8] }
6 declare void @consume(ptr)
7 declare void @consume2(ptr)
9 define ptr @f() presplitcoroutine {
11 %data = alloca i32, align 4
12 %__promise = alloca %"class.task::promise_type", align 64
13 %id = call token @llvm.coro.id(i32 0, ptr %__promise, ptr null, ptr null)
14 call void @consume2(ptr %__promise)
15 %size = call i32 @llvm.coro.size.i32()
16 %alloc = call ptr @malloc(i32 %size)
17 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
18 call void @consume(ptr %data)
19 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
20 switch i8 %0, label %suspend [i8 0, label %resume
23 call void @consume(ptr %data)
24 call void @consume2(ptr %__promise)
28 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
29 call void @free(ptr %mem)
32 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
36 ; CHECK-LABEL: %f.Frame = type { ptr, ptr, i32, i1, [43 x i8], %"class.task::promise_type" }
39 ; CHECK: %__promise = alloca %"class.task::promise_type"
40 ; CHECK: call void @consume2(ptr %__promise)
41 ; CHECK: call{{.*}}@llvm.coro.begin
42 ; CHECK: %[[PROMISE_ADDR:.+]] = getelementptr inbounds %f.Frame, ptr %hdl, i32 0, i32 5
43 ; CHECK: %[[PROMISE_VALUE:.+]] = load %"class.task::promise_type", ptr %__promise
44 ; CHECK: store %"class.task::promise_type" %[[PROMISE_VALUE]], ptr %[[PROMISE_ADDR]]
46 ; CHECK-LABEL: @f.resume(
47 ; CHECK: %[[DATA:.+]] = getelementptr inbounds %f.Frame, ptr %hdl, i32 0, i32 5
48 ; CHECK: call void @consume2(ptr %[[DATA]])
51 declare ptr @llvm.coro.free(token, ptr)
52 declare i32 @llvm.coro.size.i32()
53 declare i8 @llvm.coro.suspend(token, i1)
54 declare void @llvm.coro.resume(ptr)
55 declare void @llvm.coro.destroy(ptr)
57 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
58 declare i1 @llvm.coro.alloc(token)
59 declare ptr @llvm.coro.begin(token, ptr)
60 declare i1 @llvm.coro.end(ptr, i1, token)
62 declare noalias ptr @malloc(i32)
63 declare double @print(double)
64 declare void @free(ptr)