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(ptr)
11 declare void @reserve()
13 define void @f() personality ptr @_except_handler3 {
16 ; CHECK-NEXT: br label [[THROW:%.*]]
18 ; CHECK-NEXT: invoke void @reserve()
19 ; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]
21 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %unreachable] unwind label [[BLAH2:%.*]]
23 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
24 ; CHECK-NEXT: unreachable
26 ; CHECK-NEXT: [[CLEANUPPADI4_I_I_I:%.*]] = cleanuppad within none []
27 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
29 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[BLAH2]] ]
30 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -1
31 ; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr
32 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null
33 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
35 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
37 ; CHECK-NEXT: cleanupret from [[CLEANUPPADI4_I_I_I]] unwind to caller
42 throw: ; preds = %throw, %entry
43 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1
44 invoke void @reserve()
45 to label %throw unwind label %pad
48 %phi2 = phi ptr [ %tmp96, %throw ]
49 %cs = catchswitch within none [label %unreachable] unwind label %blah2
52 catchpad within %cs []
56 %cleanuppadi4.i.i.i = cleanuppad within none []
59 loop_body: ; preds = %iter, %pad
60 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %blah2 ]
61 %tmp100 = icmp eq ptr %tmp99, undef
62 br i1 %tmp100, label %unwind_out, label %iter
64 iter: ; preds = %loop_body
65 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1
66 br i1 true, label %unwind_out, label %loop_body
68 unwind_out: ; preds = %iter, %loop_body
69 cleanupret from %cleanuppadi4.i.i.i unwind to caller
72 define void @g() personality ptr @_except_handler3 {
75 ; CHECK-NEXT: br label [[THROW:%.*]]
77 ; CHECK-NEXT: invoke void @reserve()
78 ; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]
80 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blah] unwind to caller
82 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
83 ; CHECK-NEXT: unreachable
85 ; CHECK-NEXT: [[CATCHPAD:%.*]] = catchpad within [[CS]] []
86 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
88 ; CHECK-NEXT: catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
90 ; CHECK-NEXT: ret void
92 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[BLAH:%.*]] ]
93 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -1
94 ; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr
95 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null
96 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
98 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
103 throw: ; preds = %throw, %entry
104 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1
105 invoke void @reserve()
106 to label %throw unwind label %pad
109 %phi2 = phi ptr [ %tmp96, %throw ]
110 %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller
113 catchpad within %cs []
117 %catchpad = catchpad within %cs []
121 catchret from %catchpad to label %leave
126 loop_body: ; preds = %iter, %pad
127 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %blah ]
128 %tmp100 = icmp eq ptr %tmp99, undef
129 br i1 %tmp100, label %unwind_out, label %iter
131 iter: ; preds = %loop_body
132 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1
133 br i1 true, label %unwind_out, label %loop_body
136 define void @h() personality ptr @_except_handler3 {
139 ; CHECK-NEXT: br label [[THROW:%.*]]
141 ; CHECK-NEXT: invoke void @reserve()
142 ; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]
144 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blug] unwind to caller
145 ; CHECK: unreachable:
146 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
147 ; CHECK-NEXT: unreachable
149 ; CHECK-NEXT: [[CATCHPAD:%.*]] = catchpad within [[CS]] []
150 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
152 ; CHECK-NEXT: catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
154 ; CHECK-NEXT: ret void
156 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[BLUG:%.*]] ]
157 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -1
158 ; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr
159 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null
160 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
162 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
167 throw: ; preds = %throw, %entry
168 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1
169 invoke void @reserve()
170 to label %throw unwind label %pad
173 %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller
176 catchpad within %cs []
180 %phi2 = phi ptr [ %tmp96, %pad ]
181 %catchpad = catchpad within %cs []
185 catchret from %catchpad to label %leave
190 loop_body: ; preds = %iter, %pad
191 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %blug ]
192 %tmp100 = icmp eq ptr %tmp99, undef
193 br i1 %tmp100, label %unwind_out, label %iter
195 iter: ; preds = %loop_body
196 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1
197 br i1 true, label %unwind_out, label %loop_body
200 define void @i() personality ptr @_except_handler3 {
203 ; CHECK-NEXT: br label [[THROW:%.*]]
205 ; CHECK-NEXT: invoke void @reserve()
206 ; CHECK-NEXT: to label [[THROW]] unwind label [[CATCHPAD:%.*]]
208 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %cp_body] unwind label [[CLEANUPPAD:%.*]]
210 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []
211 ; CHECK-NEXT: br label [[LOOP_HEAD:%.*]]
213 ; CHECK-NEXT: [[TMP1:%.*]] = cleanuppad within none []
214 ; CHECK-NEXT: br label [[LOOP_HEAD]]
216 ; CHECK-NEXT: br label [[LOOP_BODY:%.*]]
218 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[LOOP_HEAD]] ]
219 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -1
220 ; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr
221 ; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null
222 ; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
224 ; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
226 ; CHECK-NEXT: unreachable
231 throw: ; preds = %throw, %entry
232 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1
233 invoke void @reserve()
234 to label %throw unwind label %catchpad
236 catchpad: ; preds = %throw
237 %phi2 = phi ptr [ %tmp96, %throw ]
238 %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad
241 catchpad within %cs []
245 cleanuppad within none []
251 loop_body: ; preds = %iter, %catchpad
252 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %loop_head ]
253 %tmp100 = icmp eq ptr %tmp99, undef
254 br i1 %tmp100, label %unwind_out, label %iter
256 iter: ; preds = %loop_body
257 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1
258 br i1 true, label %unwind_out, label %loop_body
260 unwind_out: ; preds = %iter, %loop_body
264 define void @test1(ptr %b, ptr %c) personality ptr @__CxxFrameHandler3 {
265 ; CHECK-LABEL: @test1(
267 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
269 ; CHECK-NEXT: [[D_0:%.*]] = phi ptr [ [[B:%.*]], [[ENTRY:%.*]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC:%.*]] ]
270 ; CHECK-NEXT: invoke void @external(ptr [[D_0]])
271 ; CHECK-NEXT: to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
273 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i32, ptr [[D_0]], i32 1
274 ; CHECK-NEXT: br label [[FOR_COND]]
275 ; CHECK: catch.dispatch:
276 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %catch] unwind label [[CATCH_DISPATCH_2:%.*]]
278 ; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] [ptr null, i32 64, ptr null]
279 ; CHECK-NEXT: catchret from [[TMP0]] to label [[TRY_CONT:%.*]]
281 ; CHECK-NEXT: invoke void @external(ptr [[C:%.*]])
282 ; CHECK-NEXT: to label [[TRY_CONT_7:%.*]] unwind label [[CATCH_DISPATCH_2]]
283 ; CHECK: catch.dispatch.2:
284 ; CHECK-NEXT: [[E_0:%.*]] = phi ptr [ [[C]], [[TRY_CONT]] ], [ [[B]], [[CATCH_DISPATCH]] ]
285 ; CHECK-NEXT: [[CS2:%.*]] = catchswitch within none [label %catch.4] unwind to caller
287 ; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[CS2]] [ptr null, i32 64, ptr null]
288 ; CHECK-NEXT: unreachable
290 ; CHECK-NEXT: ret void
295 for.cond: ; preds = %for.inc, %entry
296 %d.0 = phi ptr [ %b, %entry ], [ %incdec.ptr, %for.inc ]
297 invoke void @external(ptr %d.0)
298 to label %for.inc unwind label %catch.dispatch
300 for.inc: ; preds = %for.cond
301 %incdec.ptr = getelementptr inbounds i32, ptr %d.0, i32 1
304 catch.dispatch: ; preds = %for.cond
305 %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2
307 catch: ; preds = %catch.dispatch
308 %0 = catchpad within %cs [ptr null, i32 64, ptr null]
309 catchret from %0 to label %try.cont
311 try.cont: ; preds = %catch
312 invoke void @external(ptr %c)
313 to label %try.cont.7 unwind label %catch.dispatch.2
315 catch.dispatch.2: ; preds = %try.cont, %catchendblock
316 %e.0 = phi ptr [ %c, %try.cont ], [ %b, %catch.dispatch ]
317 %cs2 = catchswitch within none [label %catch.4] unwind to caller
319 catch.4: ; preds = %catch.dispatch.2
320 catchpad within %cs2 [ptr null, i32 64, ptr null]
323 try.cont.7: ; preds = %try.cont
327 define i32 @test2() personality ptr @_except_handler3 {
328 ; CHECK-LABEL: @test2(
330 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
332 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
333 ; CHECK-NEXT: invoke void @reserve()
334 ; CHECK-NEXT: to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
335 ; CHECK: catch.dispatch:
336 ; CHECK-NEXT: [[TMP18:%.*]] = catchswitch within none [label %catch.handler] unwind to caller
337 ; CHECK: catch.handler:
338 ; CHECK-NEXT: [[PHI_LCSSA:%.*]] = phi i32 [ [[PHI]], [[CATCH_DISPATCH]] ]
339 ; CHECK-NEXT: [[TMP19:%.*]] = catchpad within [[TMP18]] [ptr null]
340 ; CHECK-NEXT: catchret from [[TMP19]] to label [[DONE:%.*]]
342 ; CHECK-NEXT: ret i32 [[PHI_LCSSA]]
344 ; CHECK-NEXT: [[INC]] = add i32 [[PHI]], 1
345 ; CHECK-NEXT: br label [[FOR_BODY]]
350 for.body: ; preds = %for.inc, %entry
351 %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
352 invoke void @reserve()
353 to label %for.inc unwind label %catch.dispatch
355 catch.dispatch: ; preds = %for.body
356 %tmp18 = catchswitch within none [label %catch.handler] unwind to caller
358 catch.handler: ; preds = %catch.dispatch
359 %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
360 %tmp19 = catchpad within %tmp18 [ptr null]
361 catchret from %tmp19 to label %done
366 for.inc: ; preds = %for.body
367 %inc = add i32 %phi, 1