1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Verifies that we insert spills of PHI instruction _after) all PHI Nodes
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse,simplifycfg' -S | FileCheck %s
5 ; Verifies that the both phis are stored correctly in the coroutine frame
6 ; CHECK: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i32, i32, i1 }
8 define i8* @f(i1 %n) "coroutine.presplit"="1" {
11 ; 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*))
12 ; CHECK-NEXT: [[ALLOC:%.*]] = call i8* @malloc(i32 32)
13 ; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull i8* @llvm.coro.begin(token [[ID]], i8* [[ALLOC]])
14 ; CHECK-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[HDL]] to %f.Frame*
15 ; CHECK-NEXT: [[RESUME_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR]], i32 0, i32 0
16 ; CHECK-NEXT: store void (%f.Frame*)* @f.resume, void (%f.Frame*)** [[RESUME_ADDR]], align 8
17 ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 1
18 ; CHECK-NEXT: store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** [[DESTROY_ADDR]], align 8
19 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[N:%.*]], i32 0, i32 2
20 ; CHECK-NEXT: [[SPEC_SELECT5:%.*]] = select i1 [[N]], i32 1, i32 3
21 ; CHECK-NEXT: [[PHI2_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 3
22 ; CHECK-NEXT: store i32 [[SPEC_SELECT5]], i32* [[PHI2_SPILL_ADDR]], align 4
23 ; CHECK-NEXT: [[PHI1_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 2
24 ; CHECK-NEXT: store i32 [[SPEC_SELECT]], i32* [[PHI1_SPILL_ADDR]], align 4
25 ; CHECK-NEXT: [[INDEX_ADDR4:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 4
26 ; CHECK-NEXT: store i1 false, i1* [[INDEX_ADDR4]], align 1
27 ; CHECK-NEXT: ret i8* [[HDL]]
30 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
31 %size = call i32 @llvm.coro.size.i32()
32 %alloc = call i8* @malloc(i32 %size)
33 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
34 br i1 %n, label %begin, label %alt
39 %phi1 = phi i32 [ 0, %entry ], [ 2, %alt ]
40 %phi2 = phi i32 [ 1, %entry ], [ 3, %alt ]
42 %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
43 switch i8 %sp1, label %suspend [i8 0, label %resume
46 call i32 @print(i32 %phi1)
47 call i32 @print(i32 %phi2)
51 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
52 call void @free(i8* %mem)
55 call i1 @llvm.coro.end(i8* %hdl, i1 0)
59 declare i8* @llvm.coro.free(token, i8*)
60 declare i32 @llvm.coro.size.i32()
61 declare i8 @llvm.coro.suspend(token, i1)
62 declare void @llvm.coro.resume(i8*)
63 declare void @llvm.coro.destroy(i8*)
65 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
66 declare i1 @llvm.coro.alloc(token)
67 declare i8* @llvm.coro.begin(token, i8*)
68 declare i1 @llvm.coro.end(i8*, i1)
70 declare noalias i8* @malloc(i32)
71 declare i32 @print(i32)
72 declare void @free(i8*)