1 ; Check that we create copy the data from the alloca into the coroutine
2 ; frame slot if it was written to.
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
5 define i8* @f() "coroutine.presplit"="1" {
7 %a.addr = alloca i64 ; read-only before coro.begin
8 %a = load i64, i64* %a.addr ; cannot modify the value, don't need to copy
11 call void @use(i64* %x.addr) ; uses %x.addr before coro.begin
14 %y.cast = bitcast i64* %y.addr to i8* ; alias created and used after coro.begin
17 %flag = call i1 @check()
18 br i1 %flag, label %flag_true, label %flag_merge
21 call void @use(i64* %z.addr) ; conditionally used %z.addr
25 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
26 %size = call i32 @llvm.coro.size.i32()
27 %alloc = call i8* @myAlloc(i32 %size)
28 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
29 call void @llvm.memset.p0i8.i32(i8* %y.cast, i8 1, i32 4, i1 false)
30 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
31 switch i8 %0, label %suspend [i8 0, label %resume
34 call void @use(i64* %a.addr)
35 call void @use(i64* %x.addr)
36 call void @use(i64* %y.addr)
37 call void @use(i64* %z.addr)
41 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
42 call void @free(i8* %mem)
45 call i1 @llvm.coro.end(i8* %hdl, i1 0)
49 ; See that we added both x and y to the frame.
50 ; CHECK: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i64, i64, i64, i64, i1 }
52 ; See that all of the uses prior to coro-begin stays put.
53 ; CHECK-LABEL: define i8* @f() {
55 ; CHECK-NEXT: %a.addr = alloca i64
56 ; CHECK-NEXT: %x.addr = alloca i64
57 ; CHECK-NEXT: call void @use(i64* %x.addr)
58 ; CHECK-NEXT: %y.addr = alloca i64
59 ; CHECK-NEXT: %z.addr = alloca i64
61 ; See that we only copy the x as y was not modified prior to coro.begin.
62 ; CHECK: store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** %destroy.addr
63 ; The next 3 instructions are to copy data in %x.addr from stack to frame.
64 ; CHECK-NEXT: %0 = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 3
65 ; CHECK-NEXT: %1 = load i64, i64* %x.addr, align 4
66 ; CHECK-NEXT: store i64 %1, i64* %0, align 4
67 ; The next 2 instructions are to recreate %y.cast in the original IR.
68 ; CHECK-NEXT: %2 = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 4
69 ; CHECK-NEXT: %3 = bitcast i64* %2 to i8*
70 ; The next 3 instructions are to copy data in %z.addr from stack to frame.
71 ; CHECK-NEXT: %4 = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 5
72 ; CHECK-NEXT: %5 = load i64, i64* %z.addr, align 4
73 ; CHECK-NEXT: store i64 %5, i64* %4, align 4
74 ; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* %3, i8 1, i32 4, i1 false)
75 ; CHECK-NEXT: %index.addr1 = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 6
76 ; CHECK-NEXT: store i1 false, i1* %index.addr1, align 1
77 ; CHECK-NEXT: ret i8* %hdl
80 declare i8* @llvm.coro.free(token, i8*)
81 declare i32 @llvm.coro.size.i32()
82 declare i8 @llvm.coro.suspend(token, i1)
83 declare void @llvm.coro.resume(i8*)
84 declare void @llvm.coro.destroy(i8*)
86 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
87 declare i1 @llvm.coro.alloc(token)
88 declare i8* @llvm.coro.begin(token, i8*)
89 declare i1 @llvm.coro.end(i8*, i1)
91 declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i1)
93 declare noalias i8* @myAlloc(i32)
94 declare void @use(i64*)
95 declare void @free(i8*)