[SLP] Add cost model for `llvm.powi.*` intrinsics
[llvm-project.git] / llvm / test / Transforms / Coroutines / coro-retcon-resume-values.ll
blobcb2ff17d2edcfacf1c914c775ed8ce186af35cf5
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 i8* @f(i8* %buffer, i32 %n) {
5 ; CHECK-LABEL: @f(
6 ; CHECK-NEXT:  coro.return:
7 ; CHECK-NEXT:    [[TMP0:%.*]] = tail call i8* @allocate(i32 12)
8 ; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* [[BUFFER:%.*]] to i8**
9 ; CHECK-NEXT:    store i8* [[TMP0]], i8** [[TMP1]], align 8
10 ; CHECK-NEXT:    [[N_SPILL_ADDR:%.*]] = bitcast i8* [[TMP0]] to i32*
11 ; CHECK-NEXT:    store i32 [[N:%.*]], i32* [[N_SPILL_ADDR]], align 4
12 ; CHECK-NEXT:    ret i8* bitcast (i8* (i8*, i32, i1)* @f.resume.0 to i8*)
14 entry:
15   %id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i32, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
16   %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
17   br label %loop
19 loop:
20   %n.val = phi i32 [ %n, %entry ], [ %sum, %resume ]
21   %values = call { i32, i1 } (...) @llvm.coro.suspend.retcon.sl_i32i1s()
22   %finished = extractvalue { i32, i1 } %values, 1
23   br i1 %finished, label %cleanup, label %resume
25 resume:
26   %input = extractvalue { i32, i1 } %values, 0
27   %sum = add i32 %n.val, %input
28   br label %loop
30 cleanup:
31   call void @print(i32 %n.val)
32   call i1 @llvm.coro.end(i8* %hdl, i1 0)
33   unreachable
38 define i32 @main() {
39 ; CHECK-LABEL: @main(
40 ; CHECK-NEXT:  entry:
41 ; CHECK-NEXT:    [[TMP0:%.*]] = alloca i8*, align 8
42 ; CHECK-NEXT:    [[TMP1:%.*]] = tail call i8* @allocate(i32 12)
43 ; CHECK-NEXT:    store i8* [[TMP1]], i8** [[TMP0]], align 8
44 ; CHECK-NEXT:    [[N_SPILL_ADDR_I:%.*]] = bitcast i8* [[TMP1]] to i32*
45 ; CHECK-NEXT:    store i32 1, i32* [[N_SPILL_ADDR_I]], align 4
46 ; CHECK-NEXT:    [[TMP2:%.*]] = bitcast i8** [[TMP0]] to %f.Frame**
47 ; CHECK-NEXT:    [[N_VAL3_SPILL_ADDR_I:%.*]] = getelementptr inbounds i8, i8* [[TMP1]], i64 4
48 ; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i8* [[N_VAL3_SPILL_ADDR_I]] to i32*
49 ; CHECK-NEXT:    store i32 1, i32* [[TMP3]], align 4, !noalias !0
50 ; CHECK-NEXT:    [[INPUT_SPILL_ADDR_I:%.*]] = getelementptr inbounds i8, i8* [[TMP1]], i64 8
51 ; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i8* [[INPUT_SPILL_ADDR_I]] to i32*
52 ; CHECK-NEXT:    store i32 2, i32* [[TMP4]], align 4, !noalias !0
53 ; CHECK-NEXT:    call void @llvm.experimental.noalias.scope.decl(metadata [[META3:![0-9]+]])
54 ; CHECK-NEXT:    [[FRAMEPTR_I1:%.*]] = load %f.Frame*, %f.Frame** [[TMP2]], align 8, !alias.scope !3
55 ; CHECK-NEXT:    [[INPUT_RELOAD_ADDR13_I:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR_I1]], i64 0, i32 2
56 ; CHECK-NEXT:    [[INPUT_RELOAD14_I:%.*]] = load i32, i32* [[INPUT_RELOAD_ADDR13_I]], align 4, !noalias !3
57 ; CHECK-NEXT:    [[N_VAL3_RELOAD_ADDR11_I:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I1]], i64 0, i32 1
58 ; CHECK-NEXT:    [[N_VAL3_RELOAD12_I:%.*]] = load i32, i32* [[N_VAL3_RELOAD_ADDR11_I]], align 4, !noalias !3
59 ; CHECK-NEXT:    [[SUM7_I:%.*]] = add i32 [[N_VAL3_RELOAD12_I]], [[INPUT_RELOAD14_I]]
60 ; CHECK-NEXT:    store i32 [[SUM7_I]], i32* [[N_VAL3_RELOAD_ADDR11_I]], align 4, !noalias !3
61 ; CHECK-NEXT:    store i32 4, i32* [[INPUT_RELOAD_ADDR13_I]], align 4, !noalias !3
62 ; CHECK-NEXT:    call void @llvm.experimental.noalias.scope.decl(metadata [[META6:![0-9]+]])
63 ; CHECK-NEXT:    [[FRAMEPTR_I2:%.*]] = load %f.Frame*, %f.Frame** [[TMP2]], align 8, !alias.scope !6
64 ; CHECK-NEXT:    [[INPUT_RELOAD_ADDR13_I3:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I2]], i64 0, i32 2
65 ; CHECK-NEXT:    [[INPUT_RELOAD14_I4:%.*]] = load i32, i32* [[INPUT_RELOAD_ADDR13_I3]], align 4, !noalias !6
66 ; CHECK-NEXT:    [[N_VAL3_RELOAD_ADDR11_I5:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I2]], i64 0, i32 1
67 ; CHECK-NEXT:    [[N_VAL3_RELOAD12_I6:%.*]] = load i32, i32* [[N_VAL3_RELOAD_ADDR11_I5]], align 4, !noalias !6
68 ; CHECK-NEXT:    [[SUM7_I7:%.*]] = add i32 [[N_VAL3_RELOAD12_I6]], [[INPUT_RELOAD14_I4]]
69 ; CHECK-NEXT:    call void @print(i32 [[SUM7_I7]]), !noalias !6
70 ; CHECK-NEXT:    [[TMP5:%.*]] = bitcast %f.Frame* [[FRAMEPTR_I2]] to i8*
71 ; CHECK-NEXT:    call void @deallocate(i8* [[TMP5]]), !noalias !6
72 ; CHECK-NEXT:    ret i32 0
74 entry:
75   %0 = alloca [8 x i8], align 4
76   %buffer = bitcast [8 x i8]* %0 to i8*
77   %prepare = call i8* @llvm.coro.prepare.retcon(i8* bitcast (i8* (i8*, i32)* @f to i8*))
78   %f = bitcast i8* %prepare to i8* (i8*, i32)*
79   %cont0 = call i8* %f(i8* %buffer, i32 1)
80   %cont0.cast = bitcast i8* %cont0 to i8* (i8*, i32, i1)*
81   %cont1 = call i8* %cont0.cast(i8* %buffer, i32 2, i1 zeroext false)
82   %cont1.cast = bitcast i8* %cont1 to i8* (i8*, i32, i1)*
83   %cont2 = call i8* %cont1.cast(i8* %buffer, i32 4, i1 zeroext false)
84   %cont2.cast = bitcast i8* %cont2 to i8* (i8*, i32, i1)*
85   call i8* %cont2.cast(i8* %buffer, i32 100, i1 zeroext true)
86   ret i32 0
89 ;   Unfortunately, we don't seem to fully optimize this right now due
90 ;   to some sort of phase-ordering thing.
92 declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*)
93 declare i8* @llvm.coro.begin(token, i8*)
94 declare { i32, i1 } @llvm.coro.suspend.retcon.sl_i32i1s(...)
95 declare i1 @llvm.coro.end(i8*, i1)
96 declare i8* @llvm.coro.prepare.retcon(i8*)
98 declare i8* @prototype(i8*, i32, i1 zeroext)
100 declare noalias i8* @allocate(i32 %size)
101 declare void @deallocate(i8* %ptr)
103 declare void @print(i32)