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 i8* @f(i32 %n) "coroutine.presplit"="1" {
8 ; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* bitcast ([3 x void (%f.Frame*)*]* @f.resumers to i8*))
9 ; CHECK-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4
10 ; CHECK-NEXT: store i32 [[N:%.*]], i32* [[N_ADDR]], align 4
11 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @malloc(i32 24)
12 ; CHECK-NEXT: [[TMP0:%.*]] = tail call noalias nonnull i8* @llvm.coro.begin(token [[ID]], i8* [[CALL]])
13 ; CHECK-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[TMP0]] to %f.Frame*
14 ; CHECK-NEXT: [[RESUME_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR]], i32 0, i32 0
15 ; CHECK-NEXT: store void (%f.Frame*)* @f.resume, void (%f.Frame*)** [[RESUME_ADDR]], align 8
16 ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 1
17 ; CHECK-NEXT: store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** [[DESTROY_ADDR]], align 8
18 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 2
19 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[N_ADDR]], align 4
20 ; CHECK-NEXT: store i32 [[TMP2]], i32* [[TMP1]], align 4
23 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null);
25 store i32 %n, i32* %n.addr ; this needs to go after coro.begin
26 %0 = tail call i32 @llvm.coro.size.i32()
27 %call = tail call i8* @malloc(i32 %0)
28 %1 = tail call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %call)
29 %2 = bitcast i32* %n.addr to i8*
30 call void @ctor(i8* %2)
34 %3 = load i32, i32* %n.addr
35 %dec = add nsw i32 %3, -1
36 store i32 %dec, i32* %n.addr
37 call void @print(i32 %3)
38 %4 = call i8 @llvm.coro.suspend(token none, i1 false)
39 %conv = sext i8 %4 to i32
40 switch i32 %conv, label %coro_Suspend [
41 i32 0, label %for.cond
42 i32 1, label %coro_Cleanup
46 %5 = call i8* @llvm.coro.free(token %id, i8* nonnull %1)
47 call void @free(i8* %5)
48 br label %coro_Suspend
51 call i1 @llvm.coro.end(i8* null, i1 false)
58 %hdl = call i8* @f(i32 4)
59 call void @llvm.coro.resume(i8* %hdl)
60 call void @llvm.coro.resume(i8* %hdl)
61 call void @llvm.coro.destroy(i8* %hdl)
65 declare i8* @malloc(i32)
66 declare void @free(i8*)
67 declare void @print(i32)
68 declare void @ctor(i8* nocapture readonly)
70 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
71 declare i32 @llvm.coro.size.i32()
72 declare i8* @llvm.coro.begin(token, i8*)
73 declare i8 @llvm.coro.suspend(token, i1)
74 declare i8* @llvm.coro.free(token, i8*)
75 declare i1 @llvm.coro.end(i8*, i1)
77 declare void @llvm.coro.resume(i8*)
78 declare void @llvm.coro.destroy(i8*)