1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs
2 ; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.12.0"
7 define {ptr, i32} @f(ptr %buffer, ptr %array) {
9 %id = call token @llvm.coro.id.retcon.once(i32 8, i32 8, ptr %buffer, ptr @prototype, ptr @allocate, ptr @deallocate)
10 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
11 %load = load i32, ptr %array
12 %load.pos = icmp sgt i32 %load, 0
13 br i1 %load.pos, label %pos, label %neg
16 %unwind0 = call i1 (...) @llvm.coro.suspend.retcon.i1(i32 %load)
17 br i1 %unwind0, label %cleanup, label %pos.cont
20 store i32 0, ptr %array, align 4
24 %unwind1 = call i1 (...) @llvm.coro.suspend.retcon.i1(i32 0)
25 br i1 %unwind1, label %cleanup, label %neg.cont
28 store i32 10, ptr %array, align 4
32 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
36 define void @test.f(ptr %array) {
38 %0 = alloca [8 x i8], align 8
39 %prepare = call ptr @llvm.coro.prepare.retcon(ptr @f)
40 %result = call {ptr, i32} %prepare(ptr %0, ptr %array)
41 %value = extractvalue {ptr, i32} %result, 1
42 call void @print(i32 %value)
43 %cont = extractvalue {ptr, i32} %result, 0
44 call void %cont(ptr %0, i1 zeroext 0)
48 define {ptr, i32} @g(ptr %buffer, ptr %array, i32 %val) {
50 %id = call token @llvm.coro.id.retcon.once(i32 8, i32 8, ptr %buffer, ptr @prototype2, ptr @allocate, ptr @deallocate)
51 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
52 %load = load i32, ptr %array
53 %load.pos = icmp sgt i32 %load, 0
54 br i1 %load.pos, label %pos, label %neg
57 %unwind0 = call i1 (...) @llvm.coro.suspend.retcon.i1(i32 %load)
58 br i1 %unwind0, label %cleanup, label %pos.cont
61 store i32 0, ptr %array, align 4
65 %unwind1 = call i1 (...) @llvm.coro.suspend.retcon.i1(i32 0)
66 br i1 %unwind1, label %cleanup, label %neg.cont
69 store i32 10, ptr %array, align 4
73 %new.val = add i32 %val, 123
74 %tok = call token (...) @llvm.coro.end.results(ptr null, i32 %new.val, ptr @deallocate)
75 call i1 @llvm.coro.end(ptr %hdl, i1 0, token %tok)
79 define void @test.g(ptr %array) {
81 %0 = alloca [8 x i8], align 8
82 %prepare = call ptr @llvm.coro.prepare.retcon(ptr @f)
83 %yield.result = call {ptr, i32} %prepare(ptr %0, ptr %array)
84 %value = extractvalue {ptr, i32} %yield.result, 1
85 call void @print(i32 %value)
86 %cont = extractvalue {ptr, i32} %yield.result, 0
87 %normal.result = call {ptr, i32, ptr} %cont(ptr %0, i1 zeroext 0)
88 %value2 = extractvalue {ptr, i32, ptr} %normal.result, 1
89 call void @print(i32 %value2)
93 ; Unfortunately, we don't seem to fully optimize this right now due
94 ; to some sort of phase-ordering thing.
96 declare token @llvm.coro.id.retcon.once(i32, i32, ptr, ptr, ptr, ptr)
97 declare ptr @llvm.coro.begin(token, ptr)
98 declare i1 @llvm.coro.suspend.retcon.i1(...)
99 declare i1 @llvm.coro.end(ptr, i1, token)
100 declare token @llvm.coro.end.results(...)
101 declare ptr @llvm.coro.prepare.retcon(ptr)
103 declare void @prototype(ptr, i1 zeroext)
104 declare {ptr, i32, ptr} @prototype2(ptr, i1 zeroext)
106 declare noalias ptr @allocate(i32 %size)
107 declare void @deallocate(ptr %ptr)
109 declare void @print(i32)
112 ; CHECK-NEXT: PostSpill:
113 ; CHECK-NEXT: store ptr [[ARRAY:%.*]], ptr [[BUFFER:%.*]], align 8
114 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[ARRAY]], align 4
115 ; CHECK-NEXT: [[LOAD_POS:%.*]] = icmp sgt i32 [[LOAD]], 0
116 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[LOAD_POS]], ptr @f.resume.0, ptr @f.resume.1
117 ; CHECK-NEXT: [[SPEC_SELECT4:%.*]] = tail call i32 @llvm.smax.i32(i32 [[LOAD]], i32 0)
118 ; CHECK-NEXT: [[TMP0:%.*]] = insertvalue { ptr, i32 } poison, ptr [[SPEC_SELECT]], 0
119 ; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { ptr, i32 } [[TMP0]], i32 [[SPEC_SELECT4]], 1
120 ; CHECK-NEXT: ret { ptr, i32 } [[TMP1]]
123 ; CHECK-LABEL: @f.resume.0(
124 ; CHECK-NEXT: entryresume.0:
125 ; CHECK-NEXT: br i1 [[TMP1:%.*]], label [[COROEND:%.*]], label [[CLEANUP_SINK_SPLIT:%.*]]
126 ; CHECK: cleanup.sink.split:
127 ; CHECK-NEXT: [[ARRAY_RELOAD:%.*]] = load ptr, ptr [[TMP0:%.*]], align 8
128 ; CHECK-NEXT: store i32 0, ptr [[ARRAY_RELOAD]], align 4
129 ; CHECK-NEXT: br label [[COROEND]]
131 ; CHECK-NEXT: ret void
134 ; CHECK-LABEL: @f.resume.1(
135 ; CHECK-NEXT: entryresume.1:
136 ; CHECK-NEXT: br i1 [[TMP1:%.*]], label [[COROEND:%.*]], label [[CLEANUP_SINK_SPLIT:%.*]]
137 ; CHECK: cleanup.sink.split:
138 ; CHECK-NEXT: [[ARRAY_RELOAD:%.*]] = load ptr, ptr [[TMP0:%.*]], align 8
139 ; CHECK-NEXT: store i32 10, ptr [[ARRAY_RELOAD]], align 4
140 ; CHECK-NEXT: br label [[COROEND]]
142 ; CHECK-NEXT: ret void
145 ; CHECK-LABEL: @test.f(
147 ; CHECK-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 8
148 ; CHECK-NEXT: store ptr [[ARRAY:%.*]], ptr [[TMP0]], align 8
149 ; CHECK-NEXT: [[LOAD_I:%.*]] = load i32, ptr [[ARRAY]], align 4
150 ; CHECK-NEXT: [[LOAD_POS_I:%.*]] = icmp sgt i32 [[LOAD_I]], 0
151 ; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = select i1 [[LOAD_POS_I]], ptr @f.resume.0, ptr @f.resume.1
152 ; CHECK-NEXT: [[SPEC_SELECT4_I:%.*]] = tail call i32 @llvm.smax.i32(i32 [[LOAD_I]], i32 0)
153 ; CHECK-NEXT: tail call void @print(i32 [[SPEC_SELECT4_I]])
154 ; CHECK-NEXT: call void [[SPEC_SELECT_I]](ptr nonnull [[TMP0]], i1 zeroext false)
155 ; CHECK-NEXT: ret void
159 ; CHECK-NEXT: PostSpill:
160 ; CHECK-NEXT: [[TMP0:%.*]] = tail call ptr @allocate(i32 16)
161 ; CHECK-NEXT: store ptr [[TMP0]], ptr [[BUFFER:%.*]], align 8
162 ; CHECK-NEXT: [[VAL_SPILL_ADDR:%.*]] = getelementptr inbounds [[G_FRAME:%.*]], ptr [[TMP0]], i64 0, i32 1
163 ; CHECK-NEXT: store i32 [[VAL:%.*]], ptr [[VAL_SPILL_ADDR]], align 4
164 ; CHECK-NEXT: store ptr [[ARRAY:%.*]], ptr [[TMP0]], align 8
165 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[ARRAY]], align 4
166 ; CHECK-NEXT: [[LOAD_POS:%.*]] = icmp sgt i32 [[LOAD]], 0
167 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[LOAD_POS]], ptr @g.resume.0, ptr @g.resume.1
168 ; CHECK-NEXT: [[SPEC_SELECT4:%.*]] = tail call i32 @llvm.smax.i32(i32 [[LOAD]], i32 0)
169 ; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { ptr, i32 } poison, ptr [[SPEC_SELECT]], 0
170 ; CHECK-NEXT: [[TMP2:%.*]] = insertvalue { ptr, i32 } [[TMP1]], i32 [[SPEC_SELECT4]], 1
171 ; CHECK-NEXT: ret { ptr, i32 } [[TMP2]]
174 ; CHECK-LABEL: @g.resume.0(
175 ; CHECK-NEXT: entryresume.0:
176 ; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP0:%.*]], align 8
177 ; CHECK-NEXT: br i1 [[TMP1:%.*]], label [[COROEND:%.*]], label [[CLEANUP_SINK_SPLIT:%.*]]
178 ; CHECK: cleanup.sink.split:
179 ; CHECK-NEXT: [[ARRAY_RELOAD:%.*]] = load ptr, ptr [[TMP2]], align 8
180 ; CHECK-NEXT: store i32 0, ptr [[ARRAY_RELOAD]], align 4
181 ; CHECK-NEXT: br label [[COROEND]]
183 ; CHECK-NEXT: [[VAL_RELOAD_ADDR:%.*]] = getelementptr inbounds [[G_FRAME:%.*]], ptr [[TMP2]], i64 0, i32 1
184 ; CHECK-NEXT: [[VAL_RELOAD:%.*]] = load i32, ptr [[VAL_RELOAD_ADDR]], align 4
185 ; CHECK-NEXT: [[NEW_VAL:%.*]] = add i32 [[VAL_RELOAD]], 123
186 ; CHECK-NEXT: tail call void @deallocate(ptr [[TMP2]])
187 ; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 undef, ptr undef }, i32 [[NEW_VAL]], 1
188 ; CHECK-NEXT: [[TMP4:%.*]] = insertvalue { ptr, i32, ptr } [[TMP3]], ptr @deallocate, 2
189 ; CHECK-NEXT: ret { ptr, i32, ptr } [[TMP4]]
192 ; CHECK-LABEL: @g.resume.1(
193 ; CHECK-NEXT: entryresume.1:
194 ; CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP0:%.*]], align 8
195 ; CHECK-NEXT: br i1 [[TMP1:%.*]], label [[COROEND:%.*]], label [[CLEANUP_SINK_SPLIT:%.*]]
196 ; CHECK: cleanup.sink.split:
197 ; CHECK-NEXT: [[ARRAY_RELOAD:%.*]] = load ptr, ptr [[TMP2]], align 8
198 ; CHECK-NEXT: store i32 10, ptr [[ARRAY_RELOAD]], align 4
199 ; CHECK-NEXT: br label [[COROEND]]
201 ; CHECK-NEXT: [[VAL_RELOAD_ADDR:%.*]] = getelementptr inbounds [[G_FRAME:%.*]], ptr [[TMP2]], i64 0, i32 1
202 ; CHECK-NEXT: [[VAL_RELOAD:%.*]] = load i32, ptr [[VAL_RELOAD_ADDR]], align 4
203 ; CHECK-NEXT: [[NEW_VAL:%.*]] = add i32 [[VAL_RELOAD]], 123
204 ; CHECK-NEXT: tail call void @deallocate(ptr [[TMP2]])
205 ; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 undef, ptr undef }, i32 [[NEW_VAL]], 1
206 ; CHECK-NEXT: [[TMP4:%.*]] = insertvalue { ptr, i32, ptr } [[TMP3]], ptr @deallocate, 2
207 ; CHECK-NEXT: ret { ptr, i32, ptr } [[TMP4]]
210 ; CHECK-LABEL: @test.g(
212 ; CHECK-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 8
213 ; CHECK-NEXT: store ptr [[ARRAY:%.*]], ptr [[TMP0]], align 8
214 ; CHECK-NEXT: [[LOAD_I:%.*]] = load i32, ptr [[ARRAY]], align 4
215 ; CHECK-NEXT: [[LOAD_POS_I:%.*]] = icmp sgt i32 [[LOAD_I]], 0
216 ; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = select i1 [[LOAD_POS_I]], ptr @f.resume.0, ptr @f.resume.1
217 ; CHECK-NEXT: [[SPEC_SELECT4_I:%.*]] = tail call i32 @llvm.smax.i32(i32 [[LOAD_I]], i32 0)
218 ; CHECK-NEXT: tail call void @print(i32 [[SPEC_SELECT4_I]])
219 ; CHECK-NEXT: [[NORMAL_RESULT:%.*]] = call { ptr, i32, ptr } [[SPEC_SELECT_I]](ptr nonnull [[TMP0]], i1 zeroext false)
220 ; CHECK-NEXT: [[VALUE2:%.*]] = extractvalue { ptr, i32, ptr } [[NORMAL_RESULT]], 1
221 ; CHECK-NEXT: call void @print(i32 [[VALUE2]])
222 ; CHECK-NEXT: ret void