summaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/LoopStrengthReduce/funclet.ll
blob: c6b2029fc18d76b83e08ecb774a84eec94905eba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -loop-reduce -S | FileCheck %s

target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-pc-windows-msvc"

declare i32 @_except_handler3(...)
declare i32 @__CxxFrameHandler3(...)

declare void @external(i32*)
declare void @reserve()

define void @f() personality i32 (...)* @_except_handler3 {
; CHECK-LABEL: @f(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[THROW:%.*]]
; CHECK:       throw:
; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
; CHECK-NEXT:    invoke void @reserve()
; CHECK-NEXT:    to label [[THROW]] unwind label [[PAD:%.*]]
; CHECK:       pad:
; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label %unreachable] unwind label [[BLAH2:%.*]]
; CHECK:       unreachable:
; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
; CHECK-NEXT:    unreachable
; CHECK:       blah2:
; CHECK-NEXT:    [[CLEANUPPADI4_I_I_I:%.*]] = cleanuppad within none []
; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
; CHECK:       loop_body:
; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLAH2]] ]
; CHECK-NEXT:    [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
; CHECK:       iter:
; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
; CHECK:       unwind_out:
; CHECK-NEXT:    cleanupret from [[CLEANUPPADI4_I_I_I]] unwind to caller
;
entry:
  br label %throw

throw:                                            ; preds = %throw, %entry
  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
  invoke void @reserve()
  to label %throw unwind label %pad

pad:                                              ; preds = %throw
  %phi2 = phi i8* [ %tmp96, %throw ]
  %cs = catchswitch within none [label %unreachable] unwind label %blah2

unreachable:
  catchpad within %cs []
  unreachable

blah2:
  %cleanuppadi4.i.i.i = cleanuppad within none []
  br label %loop_body

loop_body:                                        ; preds = %iter, %pad
  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah2 ]
  %tmp100 = icmp eq i8* %tmp99, undef
  br i1 %tmp100, label %unwind_out, label %iter

iter:                                             ; preds = %loop_body
  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
  br i1 undef, label %unwind_out, label %loop_body

unwind_out:                                       ; preds = %iter, %loop_body
  cleanupret from %cleanuppadi4.i.i.i unwind to caller
}

define void @g() personality i32 (...)* @_except_handler3 {
; CHECK-LABEL: @g(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[THROW:%.*]]
; CHECK:       throw:
; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
; CHECK-NEXT:    invoke void @reserve()
; CHECK-NEXT:    to label [[THROW]] unwind label [[PAD:%.*]]
; CHECK:       pad:
; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blah] unwind to caller
; CHECK:       unreachable:
; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
; CHECK-NEXT:    unreachable
; CHECK:       blah:
; CHECK-NEXT:    [[CATCHPAD:%.*]] = catchpad within [[CS]] []
; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
; CHECK:       unwind_out:
; CHECK-NEXT:    catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
; CHECK:       leave:
; CHECK-NEXT:    ret void
; CHECK:       loop_body:
; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLAH:%.*]] ]
; CHECK-NEXT:    [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
; CHECK:       iter:
; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
;
entry:
  br label %throw

throw:                                            ; preds = %throw, %entry
  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
  invoke void @reserve()
  to label %throw unwind label %pad

pad:
  %phi2 = phi i8* [ %tmp96, %throw ]
  %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller

unreachable:
  catchpad within %cs []
  unreachable

blah:
  %catchpad = catchpad within %cs []
  br label %loop_body

unwind_out:
  catchret from %catchpad to label %leave

leave:
  ret void

loop_body:                                        ; preds = %iter, %pad
  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blah ]
  %tmp100 = icmp eq i8* %tmp99, undef
  br i1 %tmp100, label %unwind_out, label %iter

iter:                                             ; preds = %loop_body
  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
  br i1 undef, label %unwind_out, label %loop_body
}

define void @h() personality i32 (...)* @_except_handler3 {
; CHECK-LABEL: @h(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[THROW:%.*]]
; CHECK:       throw:
; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
; CHECK-NEXT:    invoke void @reserve()
; CHECK-NEXT:    to label [[THROW]] unwind label [[PAD:%.*]]
; CHECK:       pad:
; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blug] unwind to caller
; CHECK:       unreachable:
; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
; CHECK-NEXT:    unreachable
; CHECK:       blug:
; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[PAD]] ]
; CHECK-NEXT:    [[CATCHPAD:%.*]] = catchpad within [[CS]] []
; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
; CHECK:       unwind_out:
; CHECK-NEXT:    catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]
; CHECK:       leave:
; CHECK-NEXT:    ret void
; CHECK:       loop_body:
; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[BLUG:%.*]] ]
; CHECK-NEXT:    [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
; CHECK:       iter:
; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
;
entry:
  br label %throw

throw:                                            ; preds = %throw, %entry
  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
  invoke void @reserve()
  to label %throw unwind label %pad

pad:
  %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller

unreachable:
  catchpad within %cs []
  unreachable

blug:
  %phi2 = phi i8* [ %tmp96, %pad ]
  %catchpad = catchpad within %cs []
  br label %loop_body

unwind_out:
  catchret from %catchpad to label %leave

leave:
  ret void

loop_body:                                        ; preds = %iter, %pad
  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %blug ]
  %tmp100 = icmp eq i8* %tmp99, undef
  br i1 %tmp100, label %unwind_out, label %iter

iter:                                             ; preds = %loop_body
  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
  br i1 undef, label %unwind_out, label %loop_body
}

define void @i() personality i32 (...)* @_except_handler3 {
; CHECK-LABEL: @i(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[THROW:%.*]]
; CHECK:       throw:
; CHECK-NEXT:    [[TMP96:%.*]] = getelementptr inbounds i8, i8* undef, i32 1
; CHECK-NEXT:    invoke void @reserve()
; CHECK-NEXT:    to label [[THROW]] unwind label [[CATCHPAD:%.*]]
; CHECK:       catchpad:
; CHECK-NEXT:    [[PHI2:%.*]] = phi i8* [ [[TMP96]], [[THROW]] ]
; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label %cp_body] unwind label [[CLEANUPPAD:%.*]]
; CHECK:       cp_body:
; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] []
; CHECK-NEXT:    br label [[LOOP_HEAD:%.*]]
; CHECK:       cleanuppad:
; CHECK-NEXT:    [[TMP1:%.*]] = cleanuppad within none []
; CHECK-NEXT:    br label [[LOOP_HEAD]]
; CHECK:       loop_head:
; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i8, i8* [[PHI2]], i32 -1
; CHECK-NEXT:    br label [[LOOP_BODY:%.*]]
; CHECK:       loop_body:
; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP1:%.*]], [[ITER:%.*]] ], [ [[SCEVGEP]], [[LOOP_HEAD]] ]
; CHECK-NEXT:    [[SCEVGEP1]] = getelementptr i8, i8* [[LSR_IV]], i32 1
; CHECK-NEXT:    [[TMP100:%.*]] = icmp eq i8* [[SCEVGEP1]], undef
; CHECK-NEXT:    br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]
; CHECK:       iter:
; CHECK-NEXT:    br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]
; CHECK:       unwind_out:
; CHECK-NEXT:    unreachable
;
entry:
  br label %throw

throw:                                            ; preds = %throw, %entry
  %tmp96 = getelementptr inbounds i8, i8* undef, i32 1
  invoke void @reserve()
  to label %throw unwind label %catchpad

catchpad:                                              ; preds = %throw
  %phi2 = phi i8* [ %tmp96, %throw ]
  %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad

cp_body:
  catchpad within %cs []
  br label %loop_head

cleanuppad:
  cleanuppad within none []
  br label %loop_head

loop_head:
  br label %loop_body

loop_body:                                        ; preds = %iter, %catchpad
  %tmp99 = phi i8* [ %tmp101, %iter ], [ %phi2, %loop_head ]
  %tmp100 = icmp eq i8* %tmp99, undef
  br i1 %tmp100, label %unwind_out, label %iter

iter:                                             ; preds = %loop_body
  %tmp101 = getelementptr inbounds i8, i8* %tmp99, i32 1
  br i1 undef, label %unwind_out, label %loop_body

unwind_out:                                       ; preds = %iter, %loop_body
  unreachable
}

define void @test1(i32* %b, i32* %c) personality i32 (...)* @__CxxFrameHandler3 {
; CHECK-LABEL: @test1(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[FOR_COND:%.*]]
; CHECK:       for.cond:
; CHECK-NEXT:    [[D_0:%.*]] = phi i32* [ [[B:%.*]], [[ENTRY:%.*]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT:    invoke void @external(i32* [[D_0]])
; CHECK-NEXT:    to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
; CHECK:       for.inc:
; CHECK-NEXT:    [[INCDEC_PTR]] = getelementptr inbounds i32, i32* [[D_0]], i32 1
; CHECK-NEXT:    br label [[FOR_COND]]
; CHECK:       catch.dispatch:
; CHECK-NEXT:    [[CS:%.*]] = catchswitch within none [label %catch] unwind label [[CATCH_DISPATCH_2:%.*]]
; CHECK:       catch:
; CHECK-NEXT:    [[TMP0:%.*]] = catchpad within [[CS]] [i8* null, i32 64, i8* null]
; CHECK-NEXT:    catchret from [[TMP0]] to label [[TRY_CONT:%.*]]
; CHECK:       try.cont:
; CHECK-NEXT:    invoke void @external(i32* [[C:%.*]])
; CHECK-NEXT:    to label [[TRY_CONT_7:%.*]] unwind label [[CATCH_DISPATCH_2]]
; CHECK:       catch.dispatch.2:
; CHECK-NEXT:    [[E_0:%.*]] = phi i32* [ [[C]], [[TRY_CONT]] ], [ [[B]], [[CATCH_DISPATCH]] ]
; CHECK-NEXT:    [[CS2:%.*]] = catchswitch within none [label %catch.4] unwind to caller
; CHECK:       catch.4:
; CHECK-NEXT:    [[TMP1:%.*]] = catchpad within [[CS2]] [i8* null, i32 64, i8* null]
; CHECK-NEXT:    unreachable
; CHECK:       try.cont.7:
; CHECK-NEXT:    ret void
;
entry:
  br label %for.cond

for.cond:                                         ; preds = %for.inc, %entry
  %d.0 = phi i32* [ %b, %entry ], [ %incdec.ptr, %for.inc ]
  invoke void @external(i32* %d.0)
  to label %for.inc unwind label %catch.dispatch

for.inc:                                          ; preds = %for.cond
  %incdec.ptr = getelementptr inbounds i32, i32* %d.0, i32 1
  br label %for.cond

catch.dispatch:                                   ; preds = %for.cond
  %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2

catch:                                            ; preds = %catch.dispatch
  %0 = catchpad within %cs [i8* null, i32 64, i8* null]
  catchret from %0 to label %try.cont

try.cont:                                         ; preds = %catch
  invoke void @external(i32* %c)
  to label %try.cont.7 unwind label %catch.dispatch.2

catch.dispatch.2:                                 ; preds = %try.cont, %catchendblock
  %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]
  %cs2 = catchswitch within none [label %catch.4] unwind to caller

catch.4:                                          ; preds = %catch.dispatch.2
  catchpad within %cs2 [i8* null, i32 64, i8* null]
  unreachable

try.cont.7:                                       ; preds = %try.cont
  ret void
}

define i32 @test2() personality i32 (...)* @_except_handler3 {
; CHECK-LABEL: @test2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
; CHECK:       for.body:
; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]
; CHECK-NEXT:    invoke void @reserve()
; CHECK-NEXT:    to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]
; CHECK:       catch.dispatch:
; CHECK-NEXT:    [[TMP18:%.*]] = catchswitch within none [label %catch.handler] unwind to caller
; CHECK:       catch.handler:
; CHECK-NEXT:    [[PHI_LCSSA:%.*]] = phi i32 [ [[PHI]], [[CATCH_DISPATCH]] ]
; CHECK-NEXT:    [[TMP19:%.*]] = catchpad within [[TMP18]] [i8* null]
; CHECK-NEXT:    catchret from [[TMP19]] to label [[DONE:%.*]]
; CHECK:       done:
; CHECK-NEXT:    ret i32 [[PHI_LCSSA]]
; CHECK:       for.inc:
; CHECK-NEXT:    [[INC]] = add i32 [[PHI]], 1
; CHECK-NEXT:    br label [[FOR_BODY]]
;
entry:
  br label %for.body

for.body:                                         ; preds = %for.inc, %entry
  %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
  invoke void @reserve()
  to label %for.inc unwind label %catch.dispatch

catch.dispatch:                                   ; preds = %for.body
  %tmp18 = catchswitch within none [label %catch.handler] unwind to caller

catch.handler:                                    ; preds = %catch.dispatch
  %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]
  %tmp19 = catchpad within %tmp18 [i8* null]
  catchret from %tmp19 to label %done

done:
  ret i32 %phi.lcssa

for.inc:                                          ; preds = %for.body
  %inc = add i32 %phi, 1
  br label %for.body
}