1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
3 target datalayout = "E-p:32:32"
5 define ptr @f(ptr %buffer, i32 %n, ptr swifterror %errorslot) {
7 ; CHECK-NEXT: coro.return:
8 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[BUFFER:%.*]], align 4
9 ; CHECK-NEXT: tail call void @print(i32 [[N]])
10 ; CHECK-NEXT: store ptr null, ptr [[ERRORSLOT:%.*]], align 4
11 ; CHECK-NEXT: tail call void @maybeThrow(ptr nonnull swifterror [[ERRORSLOT]])
12 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[ERRORSLOT]], align 4
13 ; CHECK-NEXT: tail call void @logError(ptr [[TMP0]])
14 ; CHECK-NEXT: store ptr [[TMP0]], ptr [[ERRORSLOT]], align 4
15 ; CHECK-NEXT: ret ptr @f.resume.0
18 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, ptr %buffer, ptr @f_prototype, ptr @allocate, ptr @deallocate)
19 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
23 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
24 call void @print(i32 %n.val)
25 call void @maybeThrow(ptr swifterror %errorslot)
26 %errorload1 = load ptr, ptr %errorslot
27 call void @logError(ptr %errorload1)
28 %suspend_result = call { i1, ptr } (...) @llvm.coro.suspend.retcon.i1p0p0i8()
29 %unwind0 = extractvalue { i1, ptr } %suspend_result, 0
30 br i1 %unwind0, label %cleanup, label %resume
33 %inc = add i32 %n.val, 1
37 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
41 ; TODO: figure out a way to eliminate this
44 define ptr @g(ptr %buffer, i32 %n) {
46 ; CHECK-NEXT: coro.return:
47 ; CHECK-NEXT: [[TMP0:%.*]] = alloca swifterror ptr, align 4
48 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[BUFFER:%.*]], align 4
49 ; CHECK-NEXT: tail call void @print(i32 [[N]])
50 ; CHECK-NEXT: store ptr null, ptr [[TMP0]], align 4
51 ; CHECK-NEXT: call void @maybeThrow(ptr nonnull swifterror [[TMP0]])
52 ; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 4
53 ; CHECK-NEXT: [[DOTSPILL_ADDR:%.*]] = getelementptr inbounds [[G_FRAME:%.*]], ptr [[BUFFER]], i32 0, i32 1
54 ; CHECK-NEXT: store ptr [[TMP1]], ptr [[DOTSPILL_ADDR]], align 4
55 ; CHECK-NEXT: call void @logError(ptr [[TMP1]])
56 ; CHECK-NEXT: ret ptr @g.resume.0
59 %errorslot = alloca swifterror ptr, align 4
60 store ptr null, ptr %errorslot
61 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, ptr %buffer, ptr @g_prototype, ptr @allocate, ptr @deallocate)
62 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
66 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
67 call void @print(i32 %n.val)
68 call void @maybeThrow(ptr swifterror %errorslot)
69 %errorload1 = load ptr, ptr %errorslot
70 call void @logError(ptr %errorload1)
71 %unwind0 = call i1 (...) @llvm.coro.suspend.retcon.i1()
72 br i1 %unwind0, label %cleanup, label %resume
75 %inc = add i32 %n.val, 1
79 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
85 declare token @llvm.coro.id.retcon(i32, i32, ptr, ptr, ptr, ptr)
86 declare ptr @llvm.coro.begin(token, ptr)
87 declare { i1, ptr } @llvm.coro.suspend.retcon.i1p0p0i8(...)
88 declare i1 @llvm.coro.suspend.retcon.i1(...)
89 declare i1 @llvm.coro.end(ptr, i1, token)
90 declare ptr @llvm.coro.prepare.retcon(ptr)
92 declare ptr @f_prototype(ptr, i1 zeroext, ptr swifterror)
93 declare ptr @g_prototype(ptr, i1 zeroext)
95 declare noalias ptr @allocate(i32 %size)
96 declare void @deallocate(ptr %ptr)
98 declare void @print(i32)
99 declare void @maybeThrow(ptr swifterror)
100 declare void @logError(ptr)