1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
5 target datalayout = "p:64:64:64"
7 declare {ptr, ptr, i32} @prototype_f(ptr, i1)
8 define {ptr, ptr, i32} @f(ptr %buffer, i32 %n, { i32 } %dummy) {
10 ; CHECK-NEXT: coro.return:
11 ; CHECK-NEXT: [[N_VAL_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], ptr [[BUFFER:%.*]], i64 0, i32 1
12 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[N_VAL_SPILL_ADDR]], align 4
13 ; CHECK-NEXT: [[TMP0:%.*]] = tail call ptr @allocate(i32 [[N]])
14 ; CHECK-NEXT: store ptr [[TMP0]], ptr [[BUFFER]], align 8
15 ; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { ptr, ptr, i32 } { ptr @f.resume.0, ptr poison, i32 poison }, ptr [[TMP0]], 1
16 ; CHECK-NEXT: [[TMP2:%.*]] = insertvalue { ptr, ptr, i32 } [[TMP1]], i32 [[N]], 2
17 ; CHECK-NEXT: ret { ptr, ptr, i32 } [[TMP2]]
20 %id = call token @llvm.coro.id.retcon(i32 1024, i32 8, ptr %buffer, ptr @prototype_f, ptr @allocate, ptr @deallocate)
21 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
25 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
26 %alloca = call token @llvm.coro.alloca.alloc.i32(i32 %n.val, i32 8)
27 %ptr = call ptr @llvm.coro.alloca.get(token %alloca)
28 %unwind = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr %ptr, i32 %n.val)
29 call void @llvm.coro.alloca.free(token %alloca)
30 br i1 %unwind, label %cleanup, label %resume
33 %inc = add i32 %n.val, 1
37 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
42 declare {ptr, i32} @prototype_g(ptr, i1)
43 define {ptr, i32} @g(ptr %buffer, i32 %n) {
45 ; CHECK-NEXT: coro.return:
46 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[BUFFER:%.*]], align 4
47 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64
48 ; CHECK-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[TMP0]], align 8
49 ; CHECK-NEXT: tail call void @use(ptr nonnull [[TMP1]])
50 ; CHECK-NEXT: [[TMP2:%.*]] = insertvalue { ptr, i32 } { ptr @g.resume.0, i32 poison }, i32 [[N]], 1
51 ; CHECK-NEXT: ret { ptr, i32 } [[TMP2]]
54 %id = call token @llvm.coro.id.retcon(i32 1024, i32 8, ptr %buffer, ptr @prototype_g, ptr @allocate, ptr @deallocate)
55 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
59 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
60 %alloca = call token @llvm.coro.alloca.alloc.i32(i32 %n.val, i32 8)
61 %ptr = call ptr @llvm.coro.alloca.get(token %alloca)
62 call void @use(ptr %ptr)
63 call void @llvm.coro.alloca.free(token %alloca)
64 %unwind = call i1 (...) @llvm.coro.suspend.retcon.i1(i32 %n.val)
65 br i1 %unwind, label %cleanup, label %resume
68 %inc = add i32 %n.val, 1
72 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
76 declare token @llvm.coro.id.retcon(i32, i32, ptr, ptr, ptr, ptr)
77 declare ptr @llvm.coro.begin(token, ptr)
78 declare i1 @llvm.coro.suspend.retcon.i1(...)
79 declare void @llvm.coro.suspend.retcon.isVoid(...)
80 declare i1 @llvm.coro.end(ptr, i1, token)
81 declare ptr @llvm.coro.prepare.retcon(ptr)
82 declare token @llvm.coro.alloca.alloc.i32(i32, i32)
83 declare ptr @llvm.coro.alloca.get(token)
84 declare void @llvm.coro.alloca.free(token)
86 declare noalias ptr @allocate(i32 %size)
87 declare void @deallocate(ptr %ptr)
89 declare void @print(i32)
90 declare void @use(ptr)