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 i8* @f(i1 %n) "coroutine.presplit"="1" {
9 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
10 %size = call i32 @llvm.coro.size.i32()
11 %alloc = call i8* @malloc(i32 %size)
12 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
13 br i1 %n, label %flag_true, label %flag_false
16 %x.alias = bitcast i64* %x to i8*
17 call void @llvm.lifetime.start.p0i8(i64 8, i8* %x.alias)
21 %y.alias = bitcast i64* %y to i8*
22 call void @llvm.lifetime.start.p0i8(i64 8, i8* %y.alias)
26 %alias_phi = phi i8* [ %x.alias, %flag_true ], [ %y.alias, %flag_false ]
27 store i8 1, i8* %alias_phi
28 %sp1 = call i8 @llvm.coro.suspend(token none, i1 false)
29 switch i8 %sp1, label %suspend [i8 0, label %resume
32 call void @print(i8* %alias_phi)
36 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
37 call void @free(i8* %mem)
41 call i1 @llvm.coro.end(i8* %hdl, i1 0)
45 declare i8* @llvm.coro.free(token, i8*)
46 declare i32 @llvm.coro.size.i32()
47 declare i8 @llvm.coro.suspend(token, i1)
48 declare void @llvm.coro.resume(i8*)
49 declare void @llvm.coro.destroy(i8*)
51 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
52 declare i1 @llvm.coro.alloc(token)
53 declare i8* @llvm.coro.begin(token, i8*)
54 declare i1 @llvm.coro.end(i8*, i1)
56 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
58 declare void @print(i8*)
59 declare noalias i8* @malloc(i32)
60 declare void @free(i8*)
62 ; Verify that both x and y are put in the frame.
63 ; CHECK: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i64, i64, i8*, i1 }
67 ; 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*))
68 ; CHECK-NEXT: [[ALLOC:%.*]] = call i8* @malloc(i32 48)
69 ; CHECK-NEXT: [[HDL:%.*]] = call noalias nonnull i8* @llvm.coro.begin(token [[ID]], i8* [[ALLOC]])
70 ; CHECK-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[HDL]] to %f.Frame*
71 ; CHECK-NEXT: [[RESUME_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR]], i32 0, i32 0
72 ; CHECK-NEXT: store void (%f.Frame*)* @f.resume, void (%f.Frame*)** [[RESUME_ADDR]], align 8
73 ; CHECK-NEXT: [[DESTROY_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 1
74 ; CHECK-NEXT: store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** [[DESTROY_ADDR]], align 8
75 ; CHECK-NEXT: [[X_RELOAD_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 2
76 ; CHECK-NEXT: [[Y_RELOAD_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 3
77 ; CHECK-NEXT: br i1 [[N:%.*]], label [[FLAG_TRUE:%.*]], label [[FLAG_FALSE:%.*]]
79 ; CHECK-NEXT: [[X_ALIAS:%.*]] = bitcast i64* [[X_RELOAD_ADDR]] to i8*
80 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[X_ALIAS]])
81 ; CHECK-NEXT: br label [[MERGE:%.*]]
83 ; CHECK-NEXT: [[Y_ALIAS:%.*]] = bitcast i64* [[Y_RELOAD_ADDR]] to i8*
84 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 8, i8* [[Y_ALIAS]])
85 ; CHECK-NEXT: br label [[MERGE]]
87 ; CHECK-NEXT: [[ALIAS_PHI:%.*]] = phi i8* [ [[X_ALIAS]], [[FLAG_TRUE]] ], [ [[Y_ALIAS]], [[FLAG_FALSE]] ]
88 ; CHECK-NEXT: [[ALIAS_PHI_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 4
89 ; CHECK-NEXT: store i8* [[ALIAS_PHI]], i8** [[ALIAS_PHI_SPILL_ADDR]], align 8
90 ; CHECK-NEXT: store i8 1, i8* [[ALIAS_PHI]], align 1
91 ; CHECK-NEXT: [[INDEX_ADDR1:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR]], i32 0, i32 5
92 ; CHECK-NEXT: store i1 false, i1* [[INDEX_ADDR1]], align 1
93 ; CHECK-NEXT: ret i8* [[HDL]]
96 ; CHECK-LABEL: @f.resume(
97 ; CHECK-NEXT: entry.resume:
98 ; CHECK-NEXT: [[VFRAME:%.*]] = bitcast %f.Frame* [[FRAMEPTR:%.*]] to i8*
99 ; CHECK-NEXT: [[ALIAS_PHI_RELOAD_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR]], i32 0, i32 4
100 ; CHECK-NEXT: [[ALIAS_PHI_RELOAD:%.*]] = load i8*, i8** [[ALIAS_PHI_RELOAD_ADDR]], align 8
101 ; CHECK-NEXT: call void @print(i8* [[ALIAS_PHI_RELOAD]])
102 ; CHECK-NEXT: call void @free(i8* [[VFRAME]])
103 ; CHECK-NEXT: ret void