1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes="default<O2>" -aa-pipeline=default -S | FileCheck %s
4 define ptr @f(ptr %buffer, i32 %n) {
6 ; CHECK-NEXT: coro.return:
7 ; CHECK-NEXT: [[TMP0:%.*]] = tail call ptr @allocate(i32 12)
8 ; CHECK-NEXT: store ptr [[TMP0]], ptr [[BUFFER:%.*]], align 8
9 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[TMP0]], align 4
10 ; CHECK-NEXT: ret ptr @f.resume.0
13 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, ptr %buffer, ptr @prototype, ptr @allocate, ptr @deallocate)
14 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
18 %n.val = phi i32 [ %n, %entry ], [ %sum, %resume ]
19 %values = call { i32, i1 } (...) @llvm.coro.suspend.retcon.sl_i32i1s()
20 %finished = extractvalue { i32, i1 } %values, 1
21 br i1 %finished, label %cleanup, label %resume
24 %input = extractvalue { i32, i1 } %values, 0
25 %sum = add i32 %n.val, %input
29 call void @print(i32 %n.val)
30 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
39 ; CHECK-NEXT: [[TMP0:%.*]] = tail call ptr @allocate(i32 12)
40 ; CHECK-NEXT: store i32 1, ptr [[TMP0]], align 4
41 ; CHECK-NEXT: [[N_VAL3_SPILL_ADDR_I:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], ptr [[TMP0]], i64 0, i32 1
42 ; CHECK-NEXT: store i32 1, ptr [[N_VAL3_SPILL_ADDR_I]], align 4, !noalias !0
43 ; CHECK-NEXT: [[INPUT_SPILL_ADDR_I:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[TMP0]], i64 0, i32 2
44 ; CHECK-NEXT: store i32 2, ptr [[INPUT_SPILL_ADDR_I]], align 4, !noalias !0
45 ; CHECK-NEXT: [[INPUT_RELOAD_ADDR13_I:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[TMP0]], i64 0, i32 2
46 ; CHECK-NEXT: [[N_VAL3_RELOAD_ADDR11_I:%.*]] = getelementptr inbounds [[F_FRAME]], ptr [[TMP0]], i64 0, i32 1
47 ; CHECK-NEXT: store i32 3, ptr [[N_VAL3_RELOAD_ADDR11_I]], align 4, !noalias !3
48 ; CHECK-NEXT: store i32 4, ptr [[INPUT_RELOAD_ADDR13_I]], align 4, !noalias !3
49 ; CHECK-NEXT: tail call void @print(i32 7), !noalias !6
50 ; CHECK-NEXT: tail call void @deallocate(ptr nonnull [[TMP0]]), !noalias !6
51 ; CHECK-NEXT: ret i32 0
54 %0 = alloca [8 x i8], align 4
55 %prepare = call ptr @llvm.coro.prepare.retcon(ptr @f)
56 %cont0 = call ptr %prepare(ptr %0, i32 1)
57 %cont1 = call ptr %cont0(ptr %0, i32 2, i1 zeroext false)
58 %cont2 = call ptr %cont1(ptr %0, i32 4, i1 zeroext false)
59 call ptr %cont2(ptr %0, i32 100, i1 zeroext true)
63 ; Unfortunately, we don't seem to fully optimize this right now due
64 ; to some sort of phase-ordering thing.
66 declare token @llvm.coro.id.retcon(i32, i32, ptr, ptr, ptr, ptr)
67 declare ptr @llvm.coro.begin(token, ptr)
68 declare { i32, i1 } @llvm.coro.suspend.retcon.sl_i32i1s(...)
69 declare i1 @llvm.coro.end(ptr, i1, token)
70 declare ptr @llvm.coro.prepare.retcon(ptr)
72 declare ptr @prototype(ptr, i32, i1 zeroext)
74 declare noalias ptr @allocate(i32 %size)
75 declare void @deallocate(ptr %ptr)
77 declare void @print(i32)