1 ; Need to move users of allocas that were moved into the coroutine frame after
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
5 define nonnull ptr @f(i32 %n) presplitcoroutine {
8 ; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @f.resumers)
9 ; CHECK-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4
10 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[N_ADDR]], align 4
11 ; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @malloc(i32 24)
12 ; CHECK-NEXT: [[TMP0:%.*]] = tail call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[CALL]])
13 ; CHECK-NEXT: store ptr @f.resume, ptr [[TMP0]], align 8
14 ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], ptr [[TMP0]], i32 0, i32 1
15 ; CHECK-NEXT: store ptr @f.destroy, ptr [[DESTROY_ADDR]], align 8
16 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[TMP0]], i32 0, i32 2
17 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[N_ADDR]], align 4
18 ; CHECK-NEXT: store i32 [[TMP2]], ptr [[TMP1]], align 4
21 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null);
23 store i32 %n, ptr %n.addr ; this needs to go after coro.begin
24 %0 = tail call i32 @llvm.coro.size.i32()
25 %call = tail call ptr @malloc(i32 %0)
26 %1 = tail call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %call)
27 call void @ctor(ptr %n.addr)
31 %2 = load i32, ptr %n.addr
32 %dec = add nsw i32 %2, -1
33 store i32 %dec, ptr %n.addr
34 call void @print(i32 %2)
35 %3 = call i8 @llvm.coro.suspend(token none, i1 false)
36 %conv = sext i8 %3 to i32
37 switch i32 %conv, label %coro_Suspend [
38 i32 0, label %for.cond
39 i32 1, label %coro_Cleanup
43 %4 = call ptr @llvm.coro.free(token %id, ptr nonnull %1)
44 call void @free(ptr %4)
45 br label %coro_Suspend
48 call i1 @llvm.coro.end(ptr null, i1 false, token none)
55 %hdl = call ptr @f(i32 4)
56 call void @llvm.coro.resume(ptr %hdl)
57 call void @llvm.coro.resume(ptr %hdl)
58 call void @llvm.coro.destroy(ptr %hdl)
62 declare ptr @malloc(i32)
63 declare void @free(ptr)
64 declare void @print(i32)
65 declare void @ctor(ptr nocapture readonly)
67 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
68 declare i32 @llvm.coro.size.i32()
69 declare ptr @llvm.coro.begin(token, ptr)
70 declare i8 @llvm.coro.suspend(token, i1)
71 declare ptr @llvm.coro.free(token, ptr)
72 declare i1 @llvm.coro.end(ptr, i1, token)
74 declare void @llvm.coro.resume(ptr)
75 declare void @llvm.coro.destroy(ptr)