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 terminatepad within none [] unwind label %blah
26 %cs = catchswitch within none [label %unreachable] unwind label %blah2
29 catchpad within %cs []
33 %cleanuppadi4.i.i.i = cleanuppad within none []
36 loop_body: ; preds = %iter, %pad
37 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah2 ]
38 %tmp100 = icmp eq i8* %tmp99, undef
39 br i1 %tmp100, label %unwind_out, label %iter
41 iter: ; preds = %loop_body
42 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
43 br i1 undef, label %unwind_out, label %loop_body
45 unwind_out: ; preds = %iter, %loop_body
46 cleanupret from %cleanuppadi4.i.i.i unwind to caller
49 ; CHECK-LABEL: define void @f(
50 ; CHECK: cleanuppad within none []
51 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
53 define void @g() personality i32 (...)* @_except_handler3 {
57 throw: ; preds = %throw, %entry
58 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
59 invoke void @reserve()
60 to label %throw unwind label %pad
63 %phi2 = phi i8* [ %tmp96, %throw ]
64 %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller
67 catchpad within %cs []
71 %catchpad = catchpad within %cs []
75 catchret from %catchpad to label %leave
80 loop_body: ; preds = %iter, %pad
81 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah ]
82 %tmp100 = icmp eq i8* %tmp99, undef
83 br i1 %tmp100, label %unwind_out, label %iter
85 iter: ; preds = %loop_body
86 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
87 br i1 undef, label %unwind_out, label %loop_body
90 ; CHECK-LABEL: define void @g(
92 ; CHECK-NEXT: catchpad within %cs []
93 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
96 define void @h() personality i32 (...)* @_except_handler3 {
100 throw: ; preds = %throw, %entry
101 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
102 invoke void @reserve()
103 to label %throw unwind label %pad
106 %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller
109 catchpad within %cs []
113 %phi2 = phi i8* [ %tmp96, %pad ]
114 %catchpad = catchpad within %cs []
118 catchret from %catchpad to label %leave
123 loop_body: ; preds = %iter, %pad
124 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blug ]
125 %tmp100 = icmp eq i8* %tmp99, undef
126 br i1 %tmp100, label %unwind_out, label %iter
128 iter: ; preds = %loop_body
129 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
130 br i1 undef, label %unwind_out, label %loop_body
133 ; CHECK-LABEL: define void @h(
135 ; CHECK: catchpad within %cs []
136 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
138 define void @i() personality i32 (...)* @_except_handler3 {
142 throw: ; preds = %throw, %entry
143 %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
144 invoke void @reserve()
145 to label %throw unwind label %catchpad
147 catchpad: ; preds = %throw
148 %phi2 = phi i8* [ %tmp96, %throw ]
149 %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad
152 catchpad within %cs []
156 cleanuppad within none []
162 loop_body: ; preds = %iter, %catchpad
163 %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %loop_head ]
164 %tmp100 = icmp eq i8* %tmp99, undef
165 br i1 %tmp100, label %unwind_out, label %iter
167 iter: ; preds = %loop_body
168 %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
169 br i1 undef, label %unwind_out, label %loop_body
171 unwind_out: ; preds = %iter, %loop_body
175 ; CHECK-LABEL: define void @i(
176 ; CHECK: ptrtoint i8* %phi2 to i32
178 define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
182 for.cond: ; preds = %for.inc, %entry
183 %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
184 invoke void @external(i32* %d.0)
185 to label %for.inc unwind label %catch.dispatch
187 for.inc: ; preds = %for.cond
188 %incdec.ptr = getelementptr inbounds i32, i32* %d.0, i32 1
191 catch.dispatch: ; preds = %for.cond
192 %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2
194 catch: ; preds = %catch.dispatch
195 %0 = catchpad within %cs [i8* null, i32 64, i8* null]
196 catchret from %0 to label %try.cont
198 try.cont: ; preds = %catch
199 invoke void @external(i32* %c)
200 to label %try.cont.7 unwind label %catch.dispatch.2
202 catch.dispatch.2: ; preds = %try.cont, %catchendblock
203 %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
204 %cs2 = catchswitch within none [label %catch.4] unwind to caller
206 catch.4: ; preds = %catch.dispatch.2
207 catchpad within %cs2 [i8* null, i32 64, i8* null]
210 try.cont.7: ; preds = %try.cont
214 ; CHECK-LABEL: define void @test1(
216 ; CHECK: %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
218 ; CHECK: catch.dispatch.2:
219 ; CHECK: %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]