1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
4 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
5 target triple = "i686-pc-windows-msvc"
7 declare i32 @_except_handler3(...)
8 declare i32 @__CxxFrameHandler3(...)
10 declare void @external(i32*)
11 declare void @reserve()
13 define void @f() personality i32 (...)* @_except_handler3 {
16 ; CHECK-NEXT: br label [[THROW:%.*]]
18 ; CHECK-NEXT: [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
19 ; CHECK-NEXT: invoke void @reserve()
20 ; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]
22 ; CHECK-NEXT: [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
23 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %unreachable] unwind label [[BLAH2:%.*]]
25 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
26 ; CHECK-NEXT: unreachable
28 ; CHECK-NEXT: [[CLEANUPPADI4_I_I_I:%.*]] = cleanuppad within none []
29 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
30 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
32 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLAH2]] ]
33 ; CHECK-NEXT: [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
34 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
35 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
37 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
39 ; CHECK-NEXT: cleanupret from [[CLEANUPPADI4_I_I_I]] unwind to caller
44 throw: ; preds = %throw, %entry
45 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
46 invoke void @reserve()
47 to label %throw unwind label %pad
50 %phi2 = phi i8* [ %tmp96, %throw ]
51 %cs = catchswitch within none [label %unreachable] unwind label %blah2
54 catchpad within %cs []
58 %cleanuppadi4.i.i.i = cleanuppad within none []
61 loop_body: ; preds = %iter, %pad
62 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah2 ]
63 %tmp100 = icmp eq i8* %tmp99, undef
64 br i1 %tmp100, label %unwind_out, label %iter
66 iter: ; preds = %loop_body
67 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
68 br i1 undef, label %unwind_out, label %loop_body
70 unwind_out: ; preds = %iter, %loop_body
71 cleanupret from %cleanuppadi4.i.i.i unwind to caller
74 define void @g() personality i32 (...)* @_except_handler3 {
77 ; CHECK-NEXT: br label [[THROW:%.*]]
79 ; CHECK-NEXT: [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
80 ; CHECK-NEXT: invoke void @reserve()
81 ; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]
83 ; CHECK-NEXT: [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
84 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blah] unwind to caller
86 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
87 ; CHECK-NEXT: unreachable
89 ; CHECK-NEXT: [[CATCHPAD:%.*]] = catchpad within [[CS]] []
90 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
91 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
93 ; CHECK-NEXT: catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
95 ; CHECK-NEXT: ret void
97 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLAH:%.*]] ]
98 ; CHECK-NEXT: [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
99 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
100 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
102 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
107 throw: ; preds = %throw, %entry
108 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
109 invoke void @reserve()
110 to label %throw unwind label %pad
113 %phi2 = phi i8* [ %tmp96, %throw ]
114 %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller
117 catchpad within %cs []
121 %catchpad = catchpad within %cs []
125 catchret from %catchpad to label %leave
130 loop_body: ; preds = %iter, %pad
131 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah ]
132 %tmp100 = icmp eq i8* %tmp99, undef
133 br i1 %tmp100, label %unwind_out, label %iter
135 iter: ; preds = %loop_body
136 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
137 br i1 undef, label %unwind_out, label %loop_body
140 define void @h() personality i32 (...)* @_except_handler3 {
143 ; CHECK-NEXT: br label [[THROW:%.*]]
145 ; CHECK-NEXT: [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
146 ; CHECK-NEXT: invoke void @reserve()
147 ; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]
149 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blug] unwind to caller
150 ; CHECK: unreachable:
151 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
152 ; CHECK-NEXT: unreachable
154 ; CHECK-NEXT: [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[PAD]] ]
155 ; CHECK-NEXT: [[CATCHPAD:%.*]] = catchpad within [[CS]] []
156 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
157 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
159 ; CHECK-NEXT: catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
161 ; CHECK-NEXT: ret void
163 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLUG:%.*]] ]
164 ; CHECK-NEXT: [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
165 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
166 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
168 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
173 throw: ; preds = %throw, %entry
174 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
175 invoke void @reserve()
176 to label %throw unwind label %pad
179 %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller
182 catchpad within %cs []
186 %phi2 = phi i8* [ %tmp96, %pad ]
187 %catchpad = catchpad within %cs []
191 catchret from %catchpad to label %leave
196 loop_body: ; preds = %iter, %pad
197 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blug ]
198 %tmp100 = icmp eq i8* %tmp99, undef
199 br i1 %tmp100, label %unwind_out, label %iter
201 iter: ; preds = %loop_body
202 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
203 br i1 undef, label %unwind_out, label %loop_body
206 define void @i() personality i32 (...)* @_except_handler3 {
209 ; CHECK-NEXT: br label [[THROW:%.*]]
211 ; CHECK-NEXT: [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
212 ; CHECK-NEXT: invoke void @reserve()
213 ; CHECK-NEXT: to label [[THROW]] unwind label [[CATCHPAD:%.*]]
215 ; CHECK-NEXT: [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
216 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %cp_body] unwind label [[CLEANUPPAD:%.*]]
218 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
219 ; CHECK-NEXT: br label [[LOOP_HEAD:%.*]]
221 ; CHECK-NEXT: [[TMP1:%.*]] = cleanuppad within none []
222 ; CHECK-NEXT: br label [[LOOP_HEAD]]
224 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
225 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
227 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[LOOP_HEAD]] ]
228 ; CHECK-NEXT: [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
229 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
230 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
232 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
234 ; CHECK-NEXT: unreachable
239 throw: ; preds = %throw, %entry
240 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
241 invoke void @reserve()
242 to label %throw unwind label %catchpad
244 catchpad: ; preds = %throw
245 %phi2 = phi i8* [ %tmp96, %throw ]
246 %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad
249 catchpad within %cs []
253 cleanuppad within none []
259 loop_body: ; preds = %iter, %catchpad
260 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %loop_head ]
261 %tmp100 = icmp eq i8* %tmp99, undef
262 br i1 %tmp100, label %unwind_out, label %iter
264 iter: ; preds = %loop_body
265 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
266 br i1 undef, label %unwind_out, label %loop_body
268 unwind_out: ; preds = %iter, %loop_body
272 define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
273 ; CHECK-LABEL: @test1(
275 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
277 ; CHECK-NEXT: [[D_0:%.*]] = phi i32* [ [[B:%.*]], [[ENTRY:%.*]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC:%.*]] ]
278 ; CHECK-NEXT: invoke void @external(i32* [[D_0]])
279 ; CHECK-NEXT: to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
281 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i32, i32* [[D_0]], i32 1
282 ; CHECK-NEXT: br label [[FOR_COND]]
283 ; CHECK: catch.dispatch:
284 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %catch] unwind label [[CATCH_DISPATCH_2:%.*]]
286 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] [i8* null, i32 64, i8* null]
287 ; CHECK-NEXT: catchret from [[TMP0]] to label [[TRY_CONT:%.*]]
289 ; CHECK-NEXT: invoke void @external(i32* [[C:%.*]])
290 ; CHECK-NEXT: to label [[TRY_CONT_7:%.*]] unwind label [[CATCH_DISPATCH_2]]
291 ; CHECK: catch.dispatch.2:
292 ; CHECK-NEXT: [[E_0:%.*]] = phi i32* [ [[C]], [[TRY_CONT]] ], [ [[B]], [[CATCH_DISPATCH]] ]
293 ; CHECK-NEXT: [[CS2:%.*]] = catchswitch within none [label %catch.4] unwind to caller
295 ; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[CS2]] [i8* null, i32 64, i8* null]
296 ; CHECK-NEXT: unreachable
298 ; CHECK-NEXT: ret void
303 for.cond: ; preds = %for.inc, %entry
304 %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
305 invoke void @external(i32* %d.0)
306 to label %for.inc unwind label %catch.dispatch
308 for.inc: ; preds = %for.cond
309 %incdec.ptr = getelementptr inbounds i32, i32* %d.0, i32 1
312 catch.dispatch: ; preds = %for.cond
313 %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2
315 catch: ; preds = %catch.dispatch
316 %0 = catchpad within %cs [i8* null, i32 64, i8* null]
317 catchret from %0 to label %try.cont
319 try.cont: ; preds = %catch
320 invoke void @external(i32* %c)
321 to label %try.cont.7 unwind label %catch.dispatch.2
323 catch.dispatch.2: ; preds = %try.cont, %catchendblock
324 %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
325 %cs2 = catchswitch within none [label %catch.4] unwind to caller
327 catch.4: ; preds = %catch.dispatch.2
328 catchpad within %cs2 [i8* null, i32 64, i8* null]
331 try.cont.7: ; preds = %try.cont
335 define i32 @test2() personality i32 (...)* @_except_handler3 {
336 ; CHECK-LABEL: @test2(
338 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
340 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
341 ; CHECK-NEXT: invoke void @reserve()
342 ; CHECK-NEXT: to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
343 ; CHECK: catch.dispatch:
344 ; CHECK-NEXT: [[TMP18:%.*]] = catchswitch within none [label %catch.handler] unwind to caller
345 ; CHECK: catch.handler:
346 ; CHECK-NEXT: [[PHI_LCSSA:%.*]] = phi i32 [ [[PHI]], [[CATCH_DISPATCH]] ]
347 ; CHECK-NEXT: [[TMP19:%.*]] = catchpad within [[TMP18]] [i8* null]
348 ; CHECK-NEXT: catchret from [[TMP19]] to label [[DONE:%.*]]
350 ; CHECK-NEXT: ret i32 [[PHI_LCSSA]]
352 ; CHECK-NEXT: [[INC]] = add i32 [[PHI]], 1
353 ; CHECK-NEXT: br label [[FOR_BODY]]
358 for.body: ; preds = %for.inc, %entry
359 %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
360 invoke void @reserve()
361 to label %for.inc unwind label %catch.dispatch
363 catch.dispatch: ; preds = %for.body
364 %tmp18 = catchswitch within none [label %catch.handler] unwind to caller
366 catch.handler: ; preds = %catch.dispatch
367 %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
368 %tmp19 = catchpad within %tmp18 [i8* null]
369 catchret from %tmp19 to label %done
374 for.inc: ; preds = %for.body
375 %inc = add i32 %phi, 1