1 ; Tests that CoroSplit can succesfully determine allocas should live on the frame
2 ; if their aliases are used across suspension points through PHINode.
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
5 define ptr @f(i1 %n) presplitcoroutine {
9 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
10 %size = call i32 @llvm.coro.size.i32()
11 %alloc = call ptr @malloc(i32 %size)
12 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
13 br i1 %n, label %flag_true, label %flag_false
16 call void @llvm.lifetime.start.p0(i64 8, ptr %x)
20 call void @llvm.lifetime.start.p0(i64 8, ptr %y)
24 %alias_phi = phi ptr [ %x, %flag_true ], [ %y, %flag_false ]
25 store i8 1, ptr %alias_phi
26 %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
27 switch i8 %sp1, label %suspend [i8 0, label %resume
30 call void @print(ptr %alias_phi)
34 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
35 call void @free(ptr %mem)
39 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
43 declare ptr @llvm.coro.free(token, ptr)
44 declare i32 @llvm.coro.size.i32()
45 declare i8 @llvm.coro.suspend(token, i1)
46 declare void @llvm.coro.resume(ptr)
47 declare void @llvm.coro.destroy(ptr)
49 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
50 declare i1 @llvm.coro.alloc(token)
51 declare ptr @llvm.coro.begin(token, ptr)
52 declare i1 @llvm.coro.end(ptr, i1, token)
54 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
56 declare void @print(ptr)
57 declare noalias ptr @malloc(i32)
58 declare void @free(ptr)
60 ; Verify that both x and y are put in the frame.
61 ; CHECK: %f.Frame = type { ptr, ptr, i64, i64, ptr, i1 }
65 ; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @f.resumers)
66 ; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i32 48)
67 ; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]])
68 ; CHECK-NEXT: store ptr @f.resume, ptr [[HDL]], align 8
69 ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%f.Frame]], ptr [[HDL]], i32 0, i32 1
70 ; CHECK-NEXT: store ptr @f.destroy, ptr [[DESTROY_ADDR]], align 8
71 ; CHECK-NEXT: [[X_RELOAD_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 2
72 ; CHECK-NEXT: [[Y_RELOAD_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 3
73 ; CHECK-NEXT: br i1 [[N:%.*]], label [[MERGE:%.*]], label [[MERGE_FROM_FLAG_FALSE:%.*]]
74 ; CHECK: merge.from.flag_false:
75 ; CHECK-NEXT: br label [[MERGE:%.*]]
77 ; CHECK-NEXT: [[ALIAS_PHI:%.*]] = phi ptr [ [[Y_RELOAD_ADDR]], [[MERGE_FROM_FLAG_FALSE]] ], [ [[X_RELOAD_ADDR]], [[ENTRY:%.*]] ]
78 ; CHECK-NEXT: [[ALIAS_PHI_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 4
79 ; CHECK-NEXT: store ptr [[ALIAS_PHI]], ptr [[ALIAS_PHI_SPILL_ADDR]], align 8
80 ; CHECK-NEXT: store i8 1, ptr [[ALIAS_PHI]], align 1
81 ; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[HDL]], i32 0, i32 5
82 ; CHECK-NEXT: store i1 false, ptr [[INDEX_ADDR1]], align 1
83 ; CHECK-NEXT: ret ptr [[HDL]]
86 ; CHECK-LABEL: @f.resume(
87 ; CHECK-NEXT: entry.resume:
88 ; CHECK-NEXT: [[ALIAS_PHI_RELOAD_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], ptr [[HDL]], i32 0, i32 4
89 ; CHECK-NEXT: [[ALIAS_PHI_RELOAD:%.*]] = load ptr, ptr [[ALIAS_PHI_RELOAD_ADDR]], align 8
90 ; CHECK-NEXT: call void @print(ptr [[ALIAS_PHI_RELOAD]])
91 ; CHECK-NEXT: call void @free(ptr [[FRAMEPTR:%.*]])
92 ; CHECK-NEXT: ret void