1 ; Verifies that we insert spills of PHI instruction _after) all PHI Nodes
2 ; RUN: opt < %s -coro-split -S | FileCheck %s
4 define i8* @f(i1 %n) "coroutine.presplit"="1" {
6 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
7 %size = call i32 @llvm.coro.size.i32()
8 %alloc = call i8* @malloc(i32 %size)
9 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
10 br i1 %n, label %begin, label %alt
15 %phi1 = phi i32 [ 0, %entry ], [ 2, %alt ]
16 %phi2 = phi i32 [ 1, %entry ], [ 3, %alt ]
18 %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
19 switch i8 %sp1, label %suspend [i8 0, label %resume
22 call i32 @print(i32 %phi1)
23 call i32 @print(i32 %phi2)
27 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
28 call void @free(i8* %mem)
31 call i1 @llvm.coro.end(i8* %hdl, i1 0)
35 ; Verifies that the both phis are stored correctly in the coroutine frame
36 ; CHECK: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i1, i1, i32, i32 }
38 ; CHECK: store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** %destroy.addr
39 ; CHECK: %phi1 = select i1 %n, i32 0, i32 2
40 ; CHECK: %phi2 = select i1 %n, i32 1, i32 3
41 ; CHECK: %phi2.spill.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 5
42 ; CHECK: store i32 %phi2, i32* %phi2.spill.addr
43 ; CHECK: %phi1.spill.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 4
44 ; CHECK: store i32 %phi1, i32* %phi1.spill.addr
47 declare i8* @llvm.coro.free(token, i8*)
48 declare i32 @llvm.coro.size.i32()
49 declare i8 @llvm.coro.suspend(token, i1)
50 declare void @llvm.coro.resume(i8*)
51 declare void @llvm.coro.destroy(i8*)
53 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
54 declare i1 @llvm.coro.alloc(token)
55 declare i8* @llvm.coro.begin(token, i8*)
56 declare i1 @llvm.coro.end(i8*, i1)
58 declare noalias i8* @malloc(i32)
59 declare i32 @print(i32)
60 declare void @free(i8*)