• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -loop-reduce -S | FileCheck %s
3
4target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
5target triple = "i686-pc-windows-msvc"
6
7declare i32 @_except_handler3(...)
8declare i32 @__CxxFrameHandler3(...)
9
10declare void @external(i32*)
11declare void @reserve()
12
13define void @f() personality i32 (...)* @_except_handler3 {
14; CHECK-LABEL: @f(
15; CHECK-NEXT:  entry:
16; CHECK-NEXT:    br label [[THROW:%.*]]
17; CHECK:       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:%.*]]
21; CHECK:       pad:
22; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
23; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label %unreachable] unwind label [[BLAH2:%.*]]
24; CHECK:       unreachable:
25; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
26; CHECK-NEXT:    unreachable
27; CHECK:       blah2:
28; CHECK-NEXT:    [[CLEANUPPADI4_I_I_I:%.*]] = cleanuppad within none []
29; CHECK-NEXT:    [[PHI21:%.*]] = ptrtoint i8* [[PHI2]] to i32
30; CHECK-NEXT:    [[TMP1:%.*]] = sub i32 1, [[PHI21]]
31; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* undef, i32 [[TMP1]]
32; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
33; CHECK:       loop_body:
34; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP2:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLAH2]] ]
35; CHECK-NEXT:    [[SCEVGEP2]] = getelementptr i8, i8* [[LSR_IV]], i32 -1
36; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP2]], null
37; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
38; CHECK:       iter:
39; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
40; CHECK:       unwind_out:
41; CHECK-NEXT:    cleanupret from [[CLEANUPPADI4_I_I_I]] unwind to caller
42;
43entry:
44  br label %throw
45
46throw:                                            ; preds = %throw, %entry
47  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
48  invoke void @reserve()
49  to label %throw unwind label %pad
50
51pad:                                              ; preds = %throw
52  %phi2 = phi i8* [ %tmp96, %throw ]
53  %cs = catchswitch within none [label %unreachable] unwind label %blah2
54
55unreachable:
56  catchpad within %cs []
57  unreachable
58
59blah2:
60  %cleanuppadi4.i.i.i = cleanuppad within none []
61  br label %loop_body
62
63loop_body:                                        ; preds = %iter, %pad
64  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah2 ]
65  %tmp100 = icmp eq i8* %tmp99, undef
66  br i1 %tmp100, label %unwind_out, label %iter
67
68iter:                                             ; preds = %loop_body
69  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
70  br i1 undef, label %unwind_out, label %loop_body
71
72unwind_out:                                       ; preds = %iter, %loop_body
73  cleanupret from %cleanuppadi4.i.i.i unwind to caller
74}
75
76define void @g() personality i32 (...)* @_except_handler3 {
77; CHECK-LABEL: @g(
78; CHECK-NEXT:  entry:
79; CHECK-NEXT:    br label [[THROW:%.*]]
80; CHECK:       throw:
81; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
82; CHECK-NEXT:    invoke void @reserve()
83; CHECK-NEXT:    to label [[THROW]] unwind label [[PAD:%.*]]
84; CHECK:       pad:
85; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
86; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blah] unwind to caller
87; CHECK:       unreachable:
88; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
89; CHECK-NEXT:    unreachable
90; CHECK:       blah:
91; CHECK-NEXT:    [[CATCHPAD:%.*]] = catchpad within [[CS]] []
92; CHECK-NEXT:    [[PHI21:%.*]] = ptrtoint i8* [[PHI2]] to i32
93; CHECK-NEXT:    [[TMP1:%.*]] = sub i32 1, [[PHI21]]
94; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* undef, i32 [[TMP1]]
95; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
96; CHECK:       unwind_out:
97; CHECK-NEXT:    catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
98; CHECK:       leave:
99; CHECK-NEXT:    ret void
100; CHECK:       loop_body:
101; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP2:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLAH:%.*]] ]
102; CHECK-NEXT:    [[SCEVGEP2]] = getelementptr i8, i8* [[LSR_IV]], i32 -1
103; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP2]], null
104; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
105; CHECK:       iter:
106; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
107;
108entry:
109  br label %throw
110
111throw:                                            ; preds = %throw, %entry
112  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
113  invoke void @reserve()
114  to label %throw unwind label %pad
115
116pad:
117  %phi2 = phi i8* [ %tmp96, %throw ]
118  %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller
119
120unreachable:
121  catchpad within %cs []
122  unreachable
123
124blah:
125  %catchpad = catchpad within %cs []
126  br label %loop_body
127
128unwind_out:
129  catchret from %catchpad to label %leave
130
131leave:
132  ret void
133
134loop_body:                                        ; preds = %iter, %pad
135  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah ]
136  %tmp100 = icmp eq i8* %tmp99, undef
137  br i1 %tmp100, label %unwind_out, label %iter
138
139iter:                                             ; preds = %loop_body
140  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
141  br i1 undef, label %unwind_out, label %loop_body
142}
143
144define void @h() personality i32 (...)* @_except_handler3 {
145; CHECK-LABEL: @h(
146; CHECK-NEXT:  entry:
147; CHECK-NEXT:    br label [[THROW:%.*]]
148; CHECK:       throw:
149; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
150; CHECK-NEXT:    invoke void @reserve()
151; CHECK-NEXT:    to label [[THROW]] unwind label [[PAD:%.*]]
152; CHECK:       pad:
153; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blug] unwind to caller
154; CHECK:       unreachable:
155; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
156; CHECK-NEXT:    unreachable
157; CHECK:       blug:
158; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[PAD]] ]
159; CHECK-NEXT:    [[CATCHPAD:%.*]] = catchpad within [[CS]] []
160; CHECK-NEXT:    [[PHI21:%.*]] = ptrtoint i8* [[PHI2]] to i32
161; CHECK-NEXT:    [[TMP1:%.*]] = sub i32 1, [[PHI21]]
162; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* undef, i32 [[TMP1]]
163; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
164; CHECK:       unwind_out:
165; CHECK-NEXT:    catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
166; CHECK:       leave:
167; CHECK-NEXT:    ret void
168; CHECK:       loop_body:
169; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP2:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLUG:%.*]] ]
170; CHECK-NEXT:    [[SCEVGEP2]] = getelementptr i8, i8* [[LSR_IV]], i32 -1
171; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP2]], null
172; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
173; CHECK:       iter:
174; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
175;
176entry:
177  br label %throw
178
179throw:                                            ; preds = %throw, %entry
180  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
181  invoke void @reserve()
182  to label %throw unwind label %pad
183
184pad:
185  %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller
186
187unreachable:
188  catchpad within %cs []
189  unreachable
190
191blug:
192  %phi2 = phi i8* [ %tmp96, %pad ]
193  %catchpad = catchpad within %cs []
194  br label %loop_body
195
196unwind_out:
197  catchret from %catchpad to label %leave
198
199leave:
200  ret void
201
202loop_body:                                        ; preds = %iter, %pad
203  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blug ]
204  %tmp100 = icmp eq i8* %tmp99, undef
205  br i1 %tmp100, label %unwind_out, label %iter
206
207iter:                                             ; preds = %loop_body
208  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
209  br i1 undef, label %unwind_out, label %loop_body
210}
211
212define void @i() personality i32 (...)* @_except_handler3 {
213; CHECK-LABEL: @i(
214; CHECK-NEXT:  entry:
215; CHECK-NEXT:    br label [[THROW:%.*]]
216; CHECK:       throw:
217; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
218; CHECK-NEXT:    invoke void @reserve()
219; CHECK-NEXT:    to label [[THROW]] unwind label [[CATCHPAD:%.*]]
220; CHECK:       catchpad:
221; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
222; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label %cp_body] unwind label [[CLEANUPPAD:%.*]]
223; CHECK:       cp_body:
224; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
225; CHECK-NEXT:    br label [[LOOP_HEAD:%.*]]
226; CHECK:       cleanuppad:
227; CHECK-NEXT:    [[TMP1:%.*]] = cleanuppad within none []
228; CHECK-NEXT:    br label [[LOOP_HEAD]]
229; CHECK:       loop_head:
230; CHECK-NEXT:    [[PHI21:%.*]] = ptrtoint i8* [[PHI2]] to i32
231; CHECK-NEXT:    [[TMP2:%.*]] = sub i32 1, [[PHI21]]
232; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* undef, i32 [[TMP2]]
233; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
234; CHECK:       loop_body:
235; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP2:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[LOOP_HEAD]] ]
236; CHECK-NEXT:    [[SCEVGEP2]] = getelementptr i8, i8* [[LSR_IV]], i32 -1
237; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP2]], null
238; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
239; CHECK:       iter:
240; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
241; CHECK:       unwind_out:
242; CHECK-NEXT:    unreachable
243;
244entry:
245  br label %throw
246
247throw:                                            ; preds = %throw, %entry
248  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
249  invoke void @reserve()
250  to label %throw unwind label %catchpad
251
252catchpad:                                              ; preds = %throw
253  %phi2 = phi i8* [ %tmp96, %throw ]
254  %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad
255
256cp_body:
257  catchpad within %cs []
258  br label %loop_head
259
260cleanuppad:
261  cleanuppad within none []
262  br label %loop_head
263
264loop_head:
265  br label %loop_body
266
267loop_body:                                        ; preds = %iter, %catchpad
268  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %loop_head ]
269  %tmp100 = icmp eq i8* %tmp99, undef
270  br i1 %tmp100, label %unwind_out, label %iter
271
272iter:                                             ; preds = %loop_body
273  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
274  br i1 undef, label %unwind_out, label %loop_body
275
276unwind_out:                                       ; preds = %iter, %loop_body
277  unreachable
278}
279
280define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
281; CHECK-LABEL: @test1(
282; CHECK-NEXT:  entry:
283; CHECK-NEXT:    br label [[FOR_COND:%.*]]
284; CHECK:       for.cond:
285; CHECK-NEXT:    [[D_0:%.*]] = phi i32* [ [[B:%.*]], [[ENTRY:%.*]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC:%.*]] ]
286; CHECK-NEXT:    invoke void @external(i32* [[D_0]])
287; CHECK-NEXT:    to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
288; CHECK:       for.inc:
289; CHECK-NEXT:    [[INCDEC_PTR]] = getelementptr inbounds i32, i32* [[D_0]], i32 1
290; CHECK-NEXT:    br label [[FOR_COND]]
291; CHECK:       catch.dispatch:
292; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label %catch] unwind label [[CATCH_DISPATCH_2:%.*]]
293; CHECK:       catch:
294; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] [i8* null, i32 64, i8* null]
295; CHECK-NEXT:    catchret from [[TMP0]] to label [[TRY_CONT:%.*]]
296; CHECK:       try.cont:
297; CHECK-NEXT:    invoke void @external(i32* [[C:%.*]])
298; CHECK-NEXT:    to label [[TRY_CONT_7:%.*]] unwind label [[CATCH_DISPATCH_2]]
299; CHECK:       catch.dispatch.2:
300; CHECK-NEXT:    [[E_0:%.*]] = phi i32* [ [[C]], [[TRY_CONT]] ], [ [[B]], [[CATCH_DISPATCH]] ]
301; CHECK-NEXT:    [[CS2:%.*]] = catchswitch within none [label %catch.4] unwind to caller
302; CHECK:       catch.4:
303; CHECK-NEXT:    [[TMP1:%.*]] = catchpad within [[CS2]] [i8* null, i32 64, i8* null]
304; CHECK-NEXT:    unreachable
305; CHECK:       try.cont.7:
306; CHECK-NEXT:    ret void
307;
308entry:
309  br label %for.cond
310
311for.cond:                                         ; preds = %for.inc, %entry
312  %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
313  invoke void @external(i32* %d.0)
314  to label %for.inc unwind label %catch.dispatch
315
316for.inc:                                          ; preds = %for.cond
317  %incdec.ptr = getelementptr inbounds i32, i32* %d.0, i32 1
318  br label %for.cond
319
320catch.dispatch:                                   ; preds = %for.cond
321  %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2
322
323catch:                                            ; preds = %catch.dispatch
324  %0 = catchpad within %cs [i8* null, i32 64, i8* null]
325  catchret from %0 to label %try.cont
326
327try.cont:                                         ; preds = %catch
328  invoke void @external(i32* %c)
329  to label %try.cont.7 unwind label %catch.dispatch.2
330
331catch.dispatch.2:                                 ; preds = %try.cont, %catchendblock
332  %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
333  %cs2 = catchswitch within none [label %catch.4] unwind to caller
334
335catch.4:                                          ; preds = %catch.dispatch.2
336  catchpad within %cs2 [i8* null, i32 64, i8* null]
337  unreachable
338
339try.cont.7:                                       ; preds = %try.cont
340  ret void
341}
342
343define i32 @test2() personality i32 (...)* @_except_handler3 {
344; CHECK-LABEL: @test2(
345; CHECK-NEXT:  entry:
346; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
347; CHECK:       for.body:
348; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
349; CHECK-NEXT:    invoke void @reserve()
350; CHECK-NEXT:    to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
351; CHECK:       catch.dispatch:
352; CHECK-NEXT:    [[TMP18:%.*]] = catchswitch within none [label %catch.handler] unwind to caller
353; CHECK:       catch.handler:
354; CHECK-NEXT:    [[PHI_LCSSA:%.*]] = phi i32 [ [[PHI]], [[CATCH_DISPATCH]] ]
355; CHECK-NEXT:    [[TMP19:%.*]] = catchpad within [[TMP18]] [i8* null]
356; CHECK-NEXT:    catchret from [[TMP19]] to label [[DONE:%.*]]
357; CHECK:       done:
358; CHECK-NEXT:    ret i32 [[PHI_LCSSA]]
359; CHECK:       for.inc:
360; CHECK-NEXT:    [[INC]] = add i32 [[PHI]], 1
361; CHECK-NEXT:    br label [[FOR_BODY]]
362;
363entry:
364  br label %for.body
365
366for.body:                                         ; preds = %for.inc, %entry
367  %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
368  invoke void @reserve()
369  to label %for.inc unwind label %catch.dispatch
370
371catch.dispatch:                                   ; preds = %for.body
372  %tmp18 = catchswitch within none [label %catch.handler] unwind to caller
373
374catch.handler:                                    ; preds = %catch.dispatch
375  %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
376  %tmp19 = catchpad within %tmp18 [i8* null]
377  catchret from %tmp19 to label %done
378
379done:
380  ret i32 %phi.lcssa
381
382for.inc:                                          ; preds = %for.body
383  %inc = add i32 %phi, 1
384  br label %for.body
385}
386