1 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
3 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
4 target triple = "i686-pc-windows-msvc"
6 declare i32 @_except_handler3(...)
7 declare i32 @__CxxFrameHandler3(...)
9 declare void @external(i32*)
10 declare void @reserve()
12 define void @f() personality i32 (...)* @_except_handler3 {
16 throw: ; preds = %throw, %entry
17 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
18 invoke void @reserve()
19 to label %throw unwind label %pad
22 %phi2 = phi i8* [ %tmp96, %throw ]
23 %cs = catchswitch within none [label %unreachable] unwind label %blah2
26 catchpad within %cs []
30 %cleanuppadi4.i.i.i = cleanuppad within none []
33 loop_body: ; preds = %iter, %pad
34 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah2 ]
35 %tmp100 = icmp eq i8* %tmp99, undef
36 br i1 %tmp100, label %unwind_out, label %iter
38 iter: ; preds = %loop_body
39 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
40 br i1 undef, label %unwind_out, label %loop_body
42 unwind_out: ; preds = %iter, %loop_body
43 cleanupret from %cleanuppadi4.i.i.i unwind to caller
46 ; CHECK-LABEL: define void @f(
47 ; CHECK: cleanuppad within none []
48 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
50 define void @g() personality i32 (...)* @_except_handler3 {
54 throw: ; preds = %throw, %entry
55 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
56 invoke void @reserve()
57 to label %throw unwind label %pad
60 %phi2 = phi i8* [ %tmp96, %throw ]
61 %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller
64 catchpad within %cs []
68 %catchpad = catchpad within %cs []
72 catchret from %catchpad to label %leave
77 loop_body: ; preds = %iter, %pad
78 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah ]
79 %tmp100 = icmp eq i8* %tmp99, undef
80 br i1 %tmp100, label %unwind_out, label %iter
82 iter: ; preds = %loop_body
83 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
84 br i1 undef, label %unwind_out, label %loop_body
87 ; CHECK-LABEL: define void @g(
89 ; CHECK-NEXT: catchpad within %cs []
90 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
93 define void @h() personality i32 (...)* @_except_handler3 {
97 throw: ; preds = %throw, %entry
98 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
99 invoke void @reserve()
100 to label %throw unwind label %pad
103 %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller
106 catchpad within %cs []
110 %phi2 = phi i8* [ %tmp96, %pad ]
111 %catchpad = catchpad within %cs []
115 catchret from %catchpad to label %leave
120 loop_body: ; preds = %iter, %pad
121 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blug ]
122 %tmp100 = icmp eq i8* %tmp99, undef
123 br i1 %tmp100, label %unwind_out, label %iter
125 iter: ; preds = %loop_body
126 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
127 br i1 undef, label %unwind_out, label %loop_body
130 ; CHECK-LABEL: define void @h(
132 ; CHECK: catchpad within %cs []
133 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
135 define void @i() personality i32 (...)* @_except_handler3 {
139 throw: ; preds = %throw, %entry
140 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
141 invoke void @reserve()
142 to label %throw unwind label %catchpad
144 catchpad: ; preds = %throw
145 %phi2 = phi i8* [ %tmp96, %throw ]
146 %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad
149 catchpad within %cs []
153 cleanuppad within none []
159 loop_body: ; preds = %iter, %catchpad
160 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %loop_head ]
161 %tmp100 = icmp eq i8* %tmp99, undef
162 br i1 %tmp100, label %unwind_out, label %iter
164 iter: ; preds = %loop_body
165 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
166 br i1 undef, label %unwind_out, label %loop_body
168 unwind_out: ; preds = %iter, %loop_body
172 ; CHECK-LABEL: define void @i(
173 ; CHECK: ptrtoint i8* %phi2 to i32
175 define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
179 for.cond: ; preds = %for.inc, %entry
180 %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
181 invoke void @external(i32* %d.0)
182 to label %for.inc unwind label %catch.dispatch
184 for.inc: ; preds = %for.cond
185 %incdec.ptr = getelementptr inbounds i32, i32* %d.0, i32 1
188 catch.dispatch: ; preds = %for.cond
189 %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2
191 catch: ; preds = %catch.dispatch
192 %0 = catchpad within %cs [i8* null, i32 64, i8* null]
193 catchret from %0 to label %try.cont
195 try.cont: ; preds = %catch
196 invoke void @external(i32* %c)
197 to label %try.cont.7 unwind label %catch.dispatch.2
199 catch.dispatch.2: ; preds = %try.cont, %catchendblock
200 %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
201 %cs2 = catchswitch within none [label %catch.4] unwind to caller
203 catch.4: ; preds = %catch.dispatch.2
204 catchpad within %cs2 [i8* null, i32 64, i8* null]
207 try.cont.7: ; preds = %try.cont
211 ; CHECK-LABEL: define void @test1(
213 ; CHECK: %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
215 ; CHECK: catch.dispatch.2:
216 ; CHECK: %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
218 define i32 @test2() personality i32 (...)* @_except_handler3 {
222 for.body: ; preds = %for.inc, %entry
223 %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
224 invoke void @reserve()
225 to label %for.inc unwind label %catch.dispatch
227 catch.dispatch: ; preds = %for.body
228 %tmp18 = catchswitch within none [label %catch.handler] unwind to caller
230 catch.handler: ; preds = %catch.dispatch
231 %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
232 %tmp19 = catchpad within %tmp18 [i8* null]
233 catchret from %tmp19 to label %done
238 for.inc: ; preds = %for.body
239 %inc = add i32 %phi, 1
243 ; CHECK-LABEL: define i32 @test2(
244 ; CHECK: %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
245 ; CHECK-NEXT: catchpad within