File: copy_propagation_onone.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (665 lines) | stat: -rw-r--r-- 25,661 bytes parent folder | download
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// RUN: %target-sil-opt -copy-propagation -canonical-ossa-rewrite-borrows -enable-sil-verify-all -opt-mode=none %s | %FileCheck %s --check-prefixes=CHECK,CHECK-ONONE

class C {}

sil [ossa] @get : $@convention(thin) () -> @owned C

sil [ossa] @see : $@convention(thin) (@guaranteed C) -> ()

sil [ossa] @end : $@convention(thin) (@owned C) -> ()

sil [ossa] @other : $@convention(thin) () -> ()

// Standard -O copy-propagation behavior.
//
// CHECK-LABEL: sil [ossa] @diamond__consume_lb__use_r : {{.*}} {
// CHECK:       [[INSTANCE:%[^,]+]] = apply
// CHECK:       cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:     [[LEFT]]:
// CHECK:       apply {{%[^,]+}}([[INSTANCE]])
// CHECK:       apply {{%[^,]+}}([[INSTANCE]])
// CHECK:       br [[BOTTOM:bb[0-9]+]]
// CHECK:     [[RIGHT]]:
// CHECK:       [[COPY:%[^,]+]] = copy_value [[INSTANCE]] :
// CHECK:       apply {{%[^,]+}}([[COPY]])
// CHECK:       br [[BOTTOM]]
// CHECK:     [[BOTTOM]]:
// CHECK:       store [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'diamond__consume_lb__use_r'
sil [ossa] @diamond__consume_lb__use_r : $@convention(thin) () -> @out C {
top(%addr : $*C):
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left, right
left:
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    destroy_value %instance : $C
    apply %see(%copy) : $@convention(thin) (@guaranteed C) -> ()
    br bottom
right:
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    apply %end(%instance) : $@convention(thin) (@owned C) -> ()
    br bottom
bottom:
    store %copy to [init] %addr : $*C
    %retval = tuple ()
    return %retval : $()
}

// There is a consuming use in right.  So bottom is a consumed block.  Liveness
// is retracted up to the consume in right and up to the bottom of left.
// CHECK-LABEL: sil [ossa] @diamond__consume_r__use_l__destroy_b : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         destroy_value [[INSTANCE]] : $C
// CHECK:         br [[BOTTOM:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[BOTTOM]]
// CHECK:       [[BOTTOM]]:
// CHECK-NOT:     destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'diamond__consume_r__use_l__destroy_b'
sil [ossa] @diamond__consume_r__use_l__destroy_b : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left, right
left:
    destroy_value %copy : $C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    br bottom
right:
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br bottom
bottom:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// Only the consuming in r2 counts as a consume, so only bottom is a consumed
// block.
// CHECK-LABEL: sil [ossa] @diamond_2r__consume_r1r2__use_l__destroy_b : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT1:bb[0-9]+]]
// CHECK:       [[LEFT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE:%[^,]+]]) : $@convention(thin) (@guaranteed C) -> ()
// CHECK:         destroy_value [[INSTANCE:%[^,]+]] : $C
// CHECK:         br [[BOTTOM:bb[0-9]+]]
// CHECK:       [[RIGHT1]]:
// CHECK:         [[COPY:%[^,]+]] = copy_value [[INSTANCE:%[^,]+]] : $C
// CHECK:         apply {{%[^,]+}}([[COPY]])
// CHECK:         br [[RIGHT2:bb[0-9]+]]
// CHECK:       [[RIGHT2]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE:%[^,]+]])
// CHECK-NOT:     destroy_value
// CHECK:         br [[BOTTOM]]
// CHECK:       [[BOTTOM]]:
// CHECK-NOT: destroy_value
// CHECK-LABEL: } // end sil function 'diamond_2r__consume_r1r2__use_l__destroy_b'
sil [ossa] @diamond_2r__consume_r1r2__use_l__destroy_b : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    %copy2 = copy_value %copy : $C
    cond_br undef, left, right
left:
    destroy_value %copy : $C
    destroy_value %copy2 : $C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    br bottom
right:
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br right2
right2:
    apply %end(%copy2) : $@convention(thin) (@owned C) -> ()
    br bottom
bottom:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// There are no consuming uses, so avoiding copies doesn't entail shortening the
// lifetime.
// CHECK-LABEL: sil [ossa] @diamond__use_lr__destroy_b : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[BOTTOM:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[BOTTOM]]
// CHECK:       [[BOTTOM]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'diamond__use_lr__destroy_b'
sil [ossa] @diamond__use_lr__destroy_b : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    cond_br undef, left, right
left:
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    br bottom
right:
    apply %see(%copy) : $@convention(thin) (@guaranteed C) -> ()
    br bottom
bottom:
    destroy_value %instance : $C
    destroy_value %copy : $C
    %retval = tuple ()
    return %retval : $()
}

// Don't shorten the lifetime if there's a single consuming use.
// CHECK-LABEL: sil [ossa] @line_3__use_m__destroy_b : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         br [[MIDDLE:bb[0-9]+]]
// CHECK:       [[MIDDLE]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[BOTTOM:bb[0-9]+]]
// CHECK:       [[BOTTOM]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK-LABEL: } // end sil function 'line_3__use_m__destroy_b'
sil [ossa] @line_3__use_m__destroy_b : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    br middle
middle:
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    br bottom
bottom:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// Don't shorten the unconsumed lifetime on the left side.
// CHECK-LABEL: sil [ossa] @diamond_2l_2r__consume_r1__use_l1__destroy_l2 : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT1:bb[0-9]+]], [[RIGHT1:bb[0-9]+]]
// CHECK:       [[LEFT1]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[LEFT2:bb[0-9]+]]
// CHECK:       [[LEFT2]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:       [[RIGHT1]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK-LABEL: } // end sil function 'diamond_2l_2r__consume_r1__use_l1__destroy_l2'
sil [ossa] @diamond_2l_2r__consume_r1__use_l1__destroy_l2 : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %instance = apply %get() : $@convention(thin) () -> @owned C
    cond_br undef, left, right
left:
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    br left2
left2:
    destroy_value %instance : $C
    br bottom
right:
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    apply %end(%instance) : $@convention(thin) (@owned C) -> ()
    br right2
right2:
    br bottom
bottom:
    %retval = tuple ()
    return %retval : $()
}

// Verify that lifetime is not shortened up to boundary block if destroy was
// previously in its unique successor.
// CHECK-LABEL: sil [ossa] @doublediamond_2d2l__consume_r11_r21__use_l11__destroy_l11_l22 : $@convention(thin) () -> () {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT11:bb[0-9]+]], [[RIGHT11:bb[0-9]+]]
// CHECK:       [[LEFT11]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]]) : $@convention(thin) (@guaranteed C) -> ()
// CHECK:         br [[MIDDLE:bb[0-9]+]]
// CHECK:       [[RIGHT11]]:
// CHECK:         [[COPY:%[^,]+]] = copy_value [[INSTANCE]]
// CHECK:         apply {{%[^,]+}}([[COPY]])
// CHECK:         br [[MIDDLE]]
// CHECK:       [[MIDDLE]]:
// CHECK:         cond_br undef, [[LEFT21:bb[0-9]+]], [[RIGHT21:bb[0-9]+]]
// CHECK:       [[LEFT21]]:
// CHECK:         br [[LEFT22:bb[0-9]+]]
// CHECK:       [[LEFT22]]:
//                The main check: the destroy hasn't been hoisted.
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT21]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]
// CHECK-LABEL: } // end sil function 'doublediamond_2d2l__consume_r11_r21__use_l11__destroy_l11_l22'
sil [ossa] @doublediamond_2d2l__consume_r11_r21__use_l11__destroy_l11_l22 : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left11, right11
left11:
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    destroy_value %instance : $C
    br middle
right11:
    apply %end(%instance) : $@convention(thin) (@owned C) -> ()
    br middle
middle:
    cond_br undef, left21, right21
left21:
    br left22

left22:
    destroy_value %copy : $C
    br bottom
right21:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br bottom
bottom:
    %retval = tuple ()
    return %retval : $()
}


// Verify that we don't shrink the lifetime even when there was a destroy
// already in the barrier block (left21).
// CHECK-LABEL: sil [ossa] @doublediamond_2d2l__consume_r11_r21__use_l11__destroy_l11_l21_l22_r21 : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT11:bb[0-9]+]], [[RIGHT11:bb[0-9]+]]
// CHECK:       [[LEFT11]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[MIDDLE:bb[0-9]+]]
// CHECK:       [[RIGHT11]]:
// CHECK:         [[COPY:%[^,]+]] = copy_value [[INSTANCE]]
// CHECK:         apply {{%[^,]+}}([[COPY]])
// CHECK:         br [[MIDDLE]]
// CHECK:       [[MIDDLE]]:
// CHECK:         cond_br undef, [[LEFT21:bb[0-9]+]], [[RIGHT21:bb[0-9]+]]
// CHECK:       [[LEFT21]]:
// CHECK:         br [[LEFT22:bb[0-9]+]]
// CHECK:       [[LEFT22]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT21]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]
// CHECK:       [[EXIT]]:
// CHECK-LABEL: } // end sil function 'doublediamond_2d2l__consume_r11_r21__use_l11__destroy_l11_l21_l22_r21'
sil [ossa] @doublediamond_2d2l__consume_r11_r21__use_l11__destroy_l11_l21_l22_r21 : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left1, right1
left1:
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    destroy_value %instance : $C
    br middle
right1:
    apply %end(%instance) : $@convention(thin) (@owned C) -> ()
    br middle
middle:
    %copy2 = copy_value %copy : $C
    cond_br undef, left21, right21
left21:
    destroy_value %copy2 : $C
    br left22

left22:
    destroy_value %copy : $C
    br bottom
right21:
    destroy_value %copy2 : $C
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br bottom
bottom:
    %retval = tuple ()
    return %retval : $()
}

// Verify that lifetime ends in boundary block when there is an extra copy and
// both it and the original are destroyed in the boundary block.
// 
// CHECK-LABEL: sil [ossa] @doublediamond__consume_r11_r21__use_l11__destroy_l11_l21_r21 : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT11:bb[0-9]+]], [[RIGHT11:bb[0-9]+]]
// CHECK:       [[LEFT11]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[MIDDLE:bb[0-9]+]]
// CHECK:       [[RIGHT11]]:
// CHECK:         [[COPY:%[^,]+]] = copy_value [[INSTANCE]]
// CHECK:         apply {{%[^,]+}}([[COPY]])
// CHECK:         br [[MIDDLE]]
// CHECK:       [[MIDDLE]]:
// CHECK:         cond_br undef, [[LEFT21:bb[0-9]+]], [[RIGHT21:bb[0-9]+]]
// CHECK:       [[LEFT21]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT21]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]
// CHECK-LABEL: } // end sil function 'doublediamond__consume_r11_r21__use_l11__destroy_l11_l21_r21'
sil [ossa] @doublediamond__consume_r11_r21__use_l11__destroy_l11_l21_r21 : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left11, right11
left11:
    apply %see(%instance) : $@convention(thin) (@guaranteed C) -> ()
    destroy_value %instance : $C
    br middle
right11:
    apply %end(%instance) : $@convention(thin) (@owned C) -> ()
    br middle
middle:
    %copy2 = copy_value %copy : $C
    cond_br undef, left21, right21
left21:
    destroy_value %copy2 : $C
    destroy_value %copy : $C
    br bottom
right21:
    destroy_value %copy2 : $C
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br bottom
bottom:
    %retval = tuple ()
    return %retval : $()
}

// Verify that we don't hoist destroys up to a dead arg.
// CHECK-LABEL: sil [ossa] @line_2__def_arg_b__destroy_b : $@convention(thin) () -> () {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         br [[BOTTOM:bb[0-9]+]]([[INSTANCE]] :
// CHECK:       [[BOTTOM]]([[PHI:%[^,]+]] :
// CHECK:         apply
// CHECK:         apply
// CHECK:         destroy_value [[PHI]]
// CHECK-LABEL: } // end sil function 'line_2__def_arg_b__destroy_b'
sil [ossa] @line_2__def_arg_b__destroy_b : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %other = function_ref @other : $@convention(thin) () -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    br bottom(%instance : $C)
bottom(%phi : @owned $C):
    apply %other() : $@convention(thin) () -> ()
    apply %other() : $@convention(thin) () -> ()
    destroy_value %phi : $C
    %retval = tuple ()
    return %retval : $()
}

// Verify that when original liveness extends to the bottom of a control-flow
// merge block, if there is no subsequent consume, it continues to extend there.
//
// CHECK-LABEL: sil [ossa] @consumedAtEntry_predecessor_is_control_flow_merge : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT_TOP:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT_TOP]]:
// CHECK:         cond_br undef, [[LEFT_LEFT:bb[0-9]+]], [[LEFT_RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT_LEFT]]:
// CHECK:         br [[LEFT_BOTTOM:bb[0-9]+]]
// CHECK:       [[LEFT_RIGHT]]:
// CHECK:         br [[LEFT_BOTTOM]]
// CHECK:       [[LEFT_BOTTOM]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]
// CHECK:       [[EXIT]]:
// CHECK-LABEL: } // end sil function 'consumedAtEntry_predecessor_is_control_flow_merge'
sil [ossa] @consumedAtEntry_predecessor_is_control_flow_merge : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left_top, right

left_top:
    cond_br undef, left_left, left_right

left_left:
    br left_bottom

left_right:
    br left_bottom

left_bottom:
    destroy_value %copy : $C
    br exit

right:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br exit

exit:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// Verify that multiple live terminators only result in a single extension into
// the destination block edge.
//
// CHECK-LABEL: sil [ossa] @consumedAtEntry_predecessor_is_control_flow_merge__multiple_terminators_live : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT_TOP:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT_TOP]]:
// CHECK:         cond_br undef, [[LEFT_LEFT:bb[0-9]+]], [[LEFT_RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT_LEFT]]:
// CHECK:         br [[LEFT_BOTTOM:bb[0-9]+]]
// CHECK:       [[LEFT_RIGHT]]:
// CHECK:         br [[LEFT_BOTTOM]]
// CHECK:       [[LEFT_BOTTOM]]:
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]
// CHECK-LABEL: } // end sil function 'consumedAtEntry_predecessor_is_control_flow_merge__multiple_terminators_live'
sil [ossa] @consumedAtEntry_predecessor_is_control_flow_merge__multiple_terminators_live : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left_top, right

left_top:
    cond_br undef, left_left, left_right

left_left:
    destroy_value %copy : $C
    br left_bottom

left_right:
    destroy_value %copy : $C
    br left_bottom

left_bottom:
    br exit

right:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br exit

exit:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// Verify that a control-flow branch "grand predecessor" gets destroys in the
// right places in its successors.
// CHECK-LABEL: sil [ossa] @consumedAtEntry_predecessor_is_control_flow_branch : {{.*}} {
// CHECK:         [[REGISTER_3:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT_TOP:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT_TOP]]:
// CHECK:         cond_br undef, [[LEFT_LEFT:bb[0-9]+]], [[LEFT_RIGHT:bb[0-9]+]]
// CHECK:       [[LEFT_LEFT]]:
// CHECK:         destroy_value [[REGISTER_3]]
// CHECK:         br [[EXIT:bb[0-9]+]]
// CHECK:       [[LEFT_RIGHT]]:
// CHECK:         destroy_value [[REGISTER_3]]
// CHECK:         br [[EXIT]]
// CHECK:       [[RIGHT]]:
// CHECK:         apply {{%[^,]+}}([[REGISTER_3]])
// CHECK:         br [[EXIT]]
// CHECK-LABEL: } // end sil function 'consumedAtEntry_predecessor_is_control_flow_branch'
sil [ossa] @consumedAtEntry_predecessor_is_control_flow_branch : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left_top, right

left_top:
    destroy_value %copy : $C
    cond_br undef, left_left, left_right

left_left:
    br exit

left_right:
    br exit

right:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br exit

exit:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// Verify that a control-flow branch "grand predecessor" gets destroys in the
// right places in its successors.  When one branch has a destroy.
// CHECK-LABEL: sil [ossa] @consumedAtEntry_predecessor_is_control_flow_branch__2 : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT_TOP:bb[0-9]+]], [[RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT_TOP]]:                                              
// CHECK:         cond_br undef, [[LEFT_LEFT:bb[0-9]+]], [[LEFT_RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT_LEFT]]:                                              
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]                                          
// CHECK:       [[LEFT_RIGHT]]:                                              
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]                                          
// CHECK:       [[RIGHT]]:                                              
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]                                          
// CHECK-LABEL: } // end sil function 'consumedAtEntry_predecessor_is_control_flow_branch__2'
sil [ossa] @consumedAtEntry_predecessor_is_control_flow_branch__2 : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left_top, right

left_top:
    cond_br undef, left_left, left_right

left_left:
    destroy_value %copy : $C
    br exit

left_right:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br exit

right:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br exit

exit:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}

// Verify that a control-flow branch "grand predecessor" gets destroys in the
// right places in its successors.  When one branch has a destroy the boundary
// can be extended to.
// CHECK-LABEL: sil [ossa] @consumedAtEntry_predecessor_is_control_flow_branch__3 : {{.*}} {
// CHECK:         [[INSTANCE:%[^,]+]] = apply
// CHECK:         cond_br undef, [[LEFT_TOP:bb[0-9]+]], [[RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT_TOP]]:                                              
// CHECK:         cond_br undef, [[LEFT_LEFT:bb[0-9]+]], [[LEFT_RIGHT:bb[0-9]+]]                         
// CHECK:       [[LEFT_LEFT]]:                                              
// CHECK:         apply
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT:bb[0-9]+]]                                          
// CHECK:       [[LEFT_RIGHT]]:                                              
// CHECK:         destroy_value [[INSTANCE]]
// CHECK:         br [[EXIT]]                                          
// CHECK:       [[RIGHT]]:                                              
// CHECK:         apply {{%[^,]+}}([[INSTANCE]])
// CHECK:         br [[EXIT]]                                          
// CHECK-LABEL: } // end sil function 'consumedAtEntry_predecessor_is_control_flow_branch__3'
sil [ossa] @consumedAtEntry_predecessor_is_control_flow_branch__3 : $@convention(thin) () -> () {
top:
    %get = function_ref @get : $@convention(thin) () -> @owned C
    %see = function_ref @see : $@convention(thin) (@guaranteed C) -> ()
    %end = function_ref @end : $@convention(thin) (@owned C) -> ()
    %instance = apply %get() : $@convention(thin) () -> @owned C
    %copy = copy_value %instance : $C
    cond_br undef, left_top, right

left_top:
    cond_br undef, left_left, left_right

left_left:
    %other = function_ref @other : $@convention(thin) () -> ()
    apply %other() : $@convention(thin) () -> ()
    destroy_value %copy : $C
    br exit

left_right:
    destroy_value %copy : $C
    br exit

right:
    apply %end(%copy) : $@convention(thin) (@owned C) -> ()
    br exit

exit:
    destroy_value %instance : $C
    %retval = tuple ()
    return %retval : $()
}