1 ; Corresponding to coro-split-sink-lifetime-01.ll. This file tests that whether the CoroFrame
2 ; pass knows the operand of lifetime.start intrinsic may be GEP as well.
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse,simplifycfg' -S | FileCheck %s
5 %"struct.std::coroutine_handle" = type { i8* }
6 %"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }
7 %"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }
9 declare i8* @malloc(i64)
10 declare void @print(i32)
12 %i8.array = type { [100 x i8] }
13 declare void @consume.i8.array(%i8.array*)
15 define void @a.gep() "coroutine.presplit"="1" {
17 %ref.tmp7 = alloca %"struct.lean_future<int>::Awaiter", align 8
18 %testval = alloca %i8.array
19 %cast = getelementptr inbounds %i8.array, %i8.array* %testval, i64 0, i32 0, i64 0
20 ; lifetime of %testval starts here, but not used until await.ready.
21 call void @llvm.lifetime.start.p0i8(i64 100, i8* %cast)
22 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
23 %alloc = call i8* @malloc(i64 16) #3
24 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
26 %save = call token @llvm.coro.save(i8* null)
27 %Result.i19 = getelementptr inbounds %"struct.lean_future<int>::Awaiter", %"struct.lean_future<int>::Awaiter"* %ref.tmp7, i64 0, i32 0
28 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
29 switch i8 %suspend, label %exit [
30 i8 0, label %await.ready
34 %StrayCoroSave = call token @llvm.coro.save(i8* null)
35 %val = load i32, i32* %Result.i19
36 call void @consume.i8.array(%i8.array* %testval)
37 call void @llvm.lifetime.end.p0i8(i64 100, i8* %cast)
38 call void @print(i32 %val)
41 call i1 @llvm.coro.end(i8* null, i1 false)
44 ; CHECK-LABEL: @a.gep.resume(
45 ; CHECK: %testval = alloca %i8.array
46 ; CHECK-NEXT: getelementptr inbounds %a.gep.Frame
47 ; CHECK-NEXT: %0 = bitcast %i8.array* %testval to i8*
48 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 100, i8* %0)
49 ; CHECK-NEXT: getelementptr inbounds %"struct.lean_future<int>::Awaiter"
50 ; CHECK-NEXT: getelementptr inbounds %i8.array, %i8.array* %testval
51 ; CHECK-NEXT: %val = load i32, i32* %Result
52 ; CHECK-NEXT: call void @consume.i8.array(%i8.array* %testval)
53 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 100, i8* %cast1)
54 ; CHECK-NEXT: call void @print(i32 %val)
55 ; CHECK-NEXT: ret void
57 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
58 declare i1 @llvm.coro.alloc(token) #3
59 declare noalias nonnull i8* @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr
60 declare i64 @llvm.coro.size.i64() #5
61 declare i8* @llvm.coro.begin(token, i8* writeonly) #3
62 declare void @"\01?puts@@YAXZZ"(...)
63 declare token @llvm.coro.save(i8*) #3
64 declare i8* @llvm.coro.frame() #5
65 declare i8 @llvm.coro.suspend(token, i1) #3
66 declare void @"\01??3@YAXPEAX@Z"(i8*) local_unnamed_addr #10
67 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #2
68 declare i1 @llvm.coro.end(i8*, i1) #3
69 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #4
70 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #4