Merging r259702:
[oota-llvm.git] / test / Transforms / LoopStrengthReduce / funclet.ll
1 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
2
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"
5
6 declare i32 @_except_handler3(...)
7 declare i32 @__CxxFrameHandler3(...)
8
9 declare void @external(i32*)
10 declare void @reserve()
11
12 define void @f() personality i32 (...)* @_except_handler3 {
13 entry:
14   br label %throw
15
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
20
21 pad:                                              ; preds = %throw
22   %phi2 = phi i8* [ %tmp96, %throw ]
23   %cs = catchswitch within none [label %unreachable] unwind label %blah2
24
25 unreachable:
26   catchpad within %cs []
27   unreachable
28
29 blah2:
30   %cleanuppadi4.i.i.i = cleanuppad within none []
31   br label %loop_body
32
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
37
38 iter:                                             ; preds = %loop_body
39   %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
40   br i1 undef, label %unwind_out, label %loop_body
41
42 unwind_out:                                       ; preds = %iter, %loop_body
43   cleanupret from %cleanuppadi4.i.i.i unwind to caller
44 }
45
46 ; CHECK-LABEL: define void @f(
47 ; CHECK: cleanuppad within none []
48 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
49
50 define void @g() personality i32 (...)* @_except_handler3 {
51 entry:
52   br label %throw
53
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
58
59 pad:
60   %phi2 = phi i8* [ %tmp96, %throw ]
61   %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller
62
63 unreachable:
64   catchpad within %cs []
65   unreachable
66
67 blah:
68   %catchpad = catchpad within %cs []
69   br label %loop_body
70
71 unwind_out:
72   catchret from %catchpad to label %leave
73
74 leave:
75   ret void
76
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
81
82 iter:                                             ; preds = %loop_body
83   %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
84   br i1 undef, label %unwind_out, label %loop_body
85 }
86
87 ; CHECK-LABEL: define void @g(
88 ; CHECK: blah:
89 ; CHECK-NEXT: catchpad within %cs []
90 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
91
92
93 define void @h() personality i32 (...)* @_except_handler3 {
94 entry:
95   br label %throw
96
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
101
102 pad:
103   %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller
104
105 unreachable:
106   catchpad within %cs []
107   unreachable
108
109 blug:
110   %phi2 = phi i8* [ %tmp96, %pad ]
111   %catchpad = catchpad within %cs []
112   br label %loop_body
113
114 unwind_out:
115   catchret from %catchpad to label %leave
116
117 leave:
118   ret void
119
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
124
125 iter:                                             ; preds = %loop_body
126   %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
127   br i1 undef, label %unwind_out, label %loop_body
128 }
129
130 ; CHECK-LABEL: define void @h(
131 ; CHECK: blug:
132 ; CHECK: catchpad within %cs []
133 ; CHECK-NEXT: ptrtoint i8* %phi2 to i32
134
135 define void @i() personality i32 (...)* @_except_handler3 {
136 entry:
137   br label %throw
138
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
143
144 catchpad:                                              ; preds = %throw
145   %phi2 = phi i8* [ %tmp96, %throw ]
146   %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad
147
148 cp_body:
149   catchpad within %cs []
150   br label %loop_head
151
152 cleanuppad:
153   cleanuppad within none []
154   br label %loop_head
155
156 loop_head:
157   br label %loop_body
158
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
163
164 iter:                                             ; preds = %loop_body
165   %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
166   br i1 undef, label %unwind_out, label %loop_body
167
168 unwind_out:                                       ; preds = %iter, %loop_body
169   unreachable
170 }
171
172 ; CHECK-LABEL: define void @i(
173 ; CHECK: ptrtoint i8* %phi2 to i32
174
175 define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
176 entry:
177   br label %for.cond
178
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
183
184 for.inc:                                          ; preds = %for.cond
185   %incdec.ptr = getelementptr inbounds i32, i32* %d.0, i32 1
186   br label %for.cond
187
188 catch.dispatch:                                   ; preds = %for.cond
189   %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2
190
191 catch:                                            ; preds = %catch.dispatch
192   %0 = catchpad within %cs [i8* null, i32 64, i8* null]
193   catchret from %0 to label %try.cont
194
195 try.cont:                                         ; preds = %catch
196   invoke void @external(i32* %c)
197           to label %try.cont.7 unwind label %catch.dispatch.2
198
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
202
203 catch.4:                                          ; preds = %catch.dispatch.2
204   catchpad within %cs2 [i8* null, i32 64, i8* null]
205   unreachable
206
207 try.cont.7:                                       ; preds = %try.cont
208   ret void
209 }
210
211 ; CHECK-LABEL: define void @test1(
212 ; CHECK: for.cond:
213 ; CHECK:   %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
214
215 ; CHECK: catch.dispatch.2:
216 ; CHECK: %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
217
218 define i32 @test2() personality i32 (...)* @_except_handler3 {
219 entry:
220   br label %for.body
221
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
226
227 catch.dispatch:                                   ; preds = %for.body
228   %tmp18 = catchswitch within none [label %catch.handler] unwind to caller
229
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
234
235 done:
236   ret i32 %phi.lcssa
237
238 for.inc:                                          ; preds = %for.body
239   %inc = add i32 %phi, 1
240   br label %for.body
241 }
242
243 ; CHECK-LABEL: define i32 @test2(
244 ; CHECK:      %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
245 ; CHECK-NEXT: catchpad within