[TTI] getTypeBasedIntrinsicInstrCost - add basic handling for strided load/store...
[llvm-project.git] / llvm / test / Transforms / Coroutines / coro-frame-reuse-alloca-01.ll
blob584caa356e9b8bb2ecd4ae62182ef74038857dd4
1 ; Tests that variables in a Corotuine whose lifetime range is not overlapping each other
2 ; re-use the same slot in Coroutine frame.
3 ; RUN: opt < %s -passes='cgscc(coro-split<reuse-storage>),simplifycfg,early-cse' -S | FileCheck %s
4 %"struct.task::promise_type" = type { i8 }
5 %struct.awaitable = type { i8 }
6 %struct.big_structure = type { [500 x i8] }
7 declare ptr @malloc(i64)
8 declare void @consume(ptr)
9 define void @a(i1 zeroext %cond) presplitcoroutine {
10 entry:
11   %__promise = alloca %"struct.task::promise_type", align 1
12   %a = alloca %struct.big_structure, align 1
13   %ref.tmp7 = alloca %struct.awaitable, align 1
14   %b = alloca %struct.big_structure, align 1
15   %ref.tmp18 = alloca %struct.awaitable, align 1
16   %0 = call token @llvm.coro.id(i32 16, ptr nonnull %__promise, ptr @a, ptr null)
17   br label %init.ready
18 init.ready:
19   %1 = call noalias nonnull ptr @llvm.coro.begin(token %0, ptr null)
20   call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %__promise)
21   br i1 %cond, label %if.then, label %if.else
22 if.then:
23   call void @llvm.lifetime.start.p0(i64 500, ptr nonnull %a)
24   call void @consume(ptr nonnull %a)
25   %save = call token @llvm.coro.save(ptr null)
26   %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
27   switch i8 %suspend, label %coro.ret [
28     i8 0, label %await.ready
29     i8 1, label %cleanup1
30   ]
31 await.ready:
32   call void @llvm.lifetime.end.p0(i64 500, ptr nonnull %a)
33   br label %cleanup1
34 if.else:
35   call void @llvm.lifetime.start.p0(i64 500, ptr nonnull %b)
36   call void @consume(ptr nonnull %b)
37   %save2 = call token @llvm.coro.save(ptr null)
38   %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
39   switch i8 %suspend2, label %coro.ret [
40     i8 0, label %await2.ready
41     i8 1, label %cleanup2
42   ]
43 await2.ready:
44   call void @llvm.lifetime.end.p0(i64 500, ptr nonnull %b)
45   br label %cleanup2
46 cleanup1:
47   call void @llvm.lifetime.end.p0(i64 500, ptr nonnull %a)
48   br label %cleanup
49 cleanup2:
50   call void @llvm.lifetime.end.p0(i64 500, ptr nonnull %b)
51   br label %cleanup
52 cleanup:
53   call ptr @llvm.coro.free(token %0, ptr %1)
54   br label %coro.ret
55 coro.ret:
56   call i1 @llvm.coro.end(ptr null, i1 false, token none)
57   ret void
60 ; check that there is only one %struct.big_structure in the frame.
61 ; CHECK: %a.Frame = type { ptr, ptr, %"struct.task::promise_type", %struct.big_structure, i1 }
63 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
64 declare i1 @llvm.coro.alloc(token) #3
65 declare i64 @llvm.coro.size.i64() #5
66 declare ptr @llvm.coro.begin(token, ptr writeonly) #3
67 declare token @llvm.coro.save(ptr) #3
68 declare ptr @llvm.coro.frame() #5
69 declare i8 @llvm.coro.suspend(token, i1) #3
70 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
71 declare i1 @llvm.coro.end(ptr, i1, token) #3
72 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #4
73 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #4