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 { ptr, ptr, i32, i32, i1 }
8 define ptr @f(i1 %n) presplitcoroutine {
11 ; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @f.resumers)
12 ; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i32 32)
13 ; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]])
14 ; CHECK-NEXT: store ptr @f.resume, ptr [[HDL]], align 8
15 ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], ptr [[HDL]], i32 0, i32 1
16 ; CHECK-NEXT: store ptr @f.destroy, ptr [[DESTROY_ADDR]], align 8
17 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[N:%.*]], i32 0, i32 2
18 ; CHECK-NEXT: [[SPEC_SELECT5:%.*]] = select i1 [[N]], i32 1, i32 3
19 ; CHECK-NEXT: [[PHI2_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 3
20 ; CHECK-NEXT: store i32 [[SPEC_SELECT5]], ptr [[PHI2_SPILL_ADDR]], align 4
21 ; CHECK-NEXT: [[PHI1_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 2
22 ; CHECK-NEXT: store i32 [[SPEC_SELECT]], ptr [[PHI1_SPILL_ADDR]], align 4
23 ; CHECK-NEXT: [[INDEX_ADDR4:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 4
24 ; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR4]], align 1
25 ; CHECK-NEXT: ret ptr [[HDL]]
28 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
29 %size = call i32 @llvm.coro.size.i32()
30 %alloc = call ptr @malloc(i32 %size)
31 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
32 br i1 %n, label %begin, label %alt
37 %phi1 = phi i32 [ 0, %entry ], [ 2, %alt ]
38 %phi2 = phi i32 [ 1, %entry ], [ 3, %alt ]
40 %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
41 switch i8 %sp1, label %suspend [i8 0, label %resume
44 call i32 @print(i32 %phi1)
45 call i32 @print(i32 %phi2)
49 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
50 call void @free(ptr %mem)
53 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
57 declare ptr @llvm.coro.free(token, ptr)
58 declare i32 @llvm.coro.size.i32()
59 declare i8 @llvm.coro.suspend(token, i1)
60 declare void @llvm.coro.resume(ptr)
61 declare void @llvm.coro.destroy(ptr)
63 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
64 declare i1 @llvm.coro.alloc(token)
65 declare ptr @llvm.coro.begin(token, ptr)
66 declare i1 @llvm.coro.end(ptr, i1, token)
68 declare noalias ptr @malloc(i32)
69 declare i32 @print(i32)
70 declare void @free(ptr)