@@ -39,6 +39,9 @@ public enum FakeOptional<T> {
39
39
case some(T)
40
40
}
41
41
42
+
43
+ sil [ossa] @getKlass : $@convention(thin) () -> @owned Klass
44
+
42
45
sil @unknown : $@convention(thin) () -> ()
43
46
44
47
sil [ossa] @guaranteed_user : $@convention(thin) (@guaranteed Klass) -> ()
@@ -1506,6 +1509,122 @@ bb2:
1506
1509
unwind
1507
1510
}
1508
1511
1512
+ // CHECK-LABEL: sil [ossa] @take_from_original_copy_addr__final_use_load_take : {{.*}} {
1513
+ // CHECK: [[GET:%[^,]+]] = function_ref @getKlass
1514
+ // CHECK: [[USER:%[^,]+]] = function_ref @inguaranteed_user_without_result
1515
+ // CHECK: [[INSTANCE_1:%[^,]+]] = apply [[GET]]()
1516
+ // CHECK: [[ADDR:%[^,]+]] = alloc_stack $Klass
1517
+ // CHECK: store [[INSTANCE_1]] to [init] [[ADDR]]
1518
+ // CHECK: apply [[USER]]([[ADDR]])
1519
+ // CHECK: [[INSTANCE_2:%[^,]+]] = load [copy] [[ADDR]]
1520
+ // Extra copy: ^^^^^^^^^^^
1521
+ // CHECK: destroy_addr [[ADDR]]
1522
+ // CHECK: dealloc_stack [[ADDR]]
1523
+ // CHECK: return [[INSTANCE_2]]
1524
+ // CHECK-LABEL: } // end sil function 'take_from_original_copy_addr__final_use_load_take'
1525
+ sil [ossa] @take_from_original_copy_addr__final_use_load_take : $() -> @owned Klass {
1526
+ %getKlass = function_ref @getKlass : $@convention(thin) () -> @owned Klass
1527
+ %user = function_ref @inguaranteed_user_without_result : $@convention(thin) (@in_guaranteed Klass) -> ()
1528
+ %instance_1 = apply %getKlass() : $@convention(thin) () -> @owned Klass
1529
+ %src = alloc_stack $Klass
1530
+ store %instance_1 to [init] %src : $*Klass
1531
+ apply %user(%src) : $@convention(thin) (@in_guaranteed Klass) -> ()
1532
+ %tmp = alloc_stack $Klass
1533
+ copy_addr [take] %src to [init] %tmp : $*Klass
1534
+ %instance_2 = load [take] %tmp : $*Klass
1535
+ dealloc_stack %tmp : $*Klass
1536
+ dealloc_stack %src : $*Klass
1537
+ return %instance_2 : $Klass
1538
+ }
1539
+
1540
+ // CHECK-LABEL: sil [ossa] @take_from_original_copy_addr__final_use_copy_addr_take : {{.*}} {
1541
+ // CHECK: {{bb[0-9]+}}([[OUT:%[^,]+]] :
1542
+ // CHECK: [[GET:%[^,]+]] = function_ref @getKlass
1543
+ // CHECK: [[USER:%[^,]+]] = function_ref @inguaranteed_user_without_result
1544
+ // CHECK: [[INSTANCE_1:%[^,]+]] = apply [[GET]]()
1545
+ // CHECK: [[SRC:%[^,]+]] = alloc_stack $Klass
1546
+ // CHECK: store [[INSTANCE_1]] to [init] [[SRC]]
1547
+ // CHECK: apply [[USER]]([[SRC]])
1548
+ // CHECK: copy_addr [[SRC]] to [init] [[OUT]]
1549
+ // Extra copy: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1550
+ // CHECK: destroy_addr [[SRC]]
1551
+ // CHECK: dealloc_stack [[SRC]]
1552
+ // CHECK-LABEL: } // end sil function 'take_from_original_copy_addr__final_use_copy_addr_take'
1553
+ sil [ossa] @take_from_original_copy_addr__final_use_copy_addr_take : $() -> @out Klass {
1554
+ entry(%out : $*Klass):
1555
+ %getKlass = function_ref @getKlass : $@convention(thin) () -> @owned Klass
1556
+ %user = function_ref @inguaranteed_user_without_result : $@convention(thin) (@in_guaranteed Klass) -> ()
1557
+ %instance_1 = apply %getKlass() : $@convention(thin) () -> @owned Klass
1558
+ %src = alloc_stack $Klass
1559
+ store %instance_1 to [init] %src : $*Klass
1560
+ apply %user(%src) : $@convention(thin) (@in_guaranteed Klass) -> ()
1561
+ %tmp = alloc_stack $Klass
1562
+ copy_addr [take] %src to [init] %tmp : $*Klass
1563
+ copy_addr [take] %tmp to [init] %out : $*Klass
1564
+ dealloc_stack %tmp : $*Klass
1565
+ dealloc_stack %src : $*Klass
1566
+ %retval = tuple ()
1567
+ return %retval : $()
1568
+ }
1569
+
1570
+ // CHECK-LABEL: sil [ossa] @take_from_original_copy_addr__final_use_load_copy : {{.*}} {
1571
+ // CHECK: [[GET:%[^,]+]] = function_ref @getKlass
1572
+ // CHECK: [[USER:%[^,]+]] = function_ref @inguaranteed_user_without_result
1573
+ // CHECK: [[INSTANCE_1:%[^,]+]] = apply [[GET]]()
1574
+ // CHECK: [[SRC:%[^,]+]] = alloc_stack $Klass
1575
+ // CHECK: store [[INSTANCE_1]] to [init] [[SRC]]
1576
+ // CHECK: apply [[USER]]([[SRC]])
1577
+ // CHECK: [[INSTANCE_2:%[^,]+]] = load [copy] [[SRC]]
1578
+ // CHECK: destroy_addr [[SRC]]
1579
+ // CHECK: dealloc_stack [[SRC]]
1580
+ // CHECK: return [[INSTANCE_2]]
1581
+ // CHECK-LABEL: } // end sil function 'take_from_original_copy_addr__final_use_load_copy'
1582
+ sil [ossa] @take_from_original_copy_addr__final_use_load_copy : $() -> @owned Klass {
1583
+ %getKlass = function_ref @getKlass : $@convention(thin) () -> @owned Klass
1584
+ %user = function_ref @inguaranteed_user_without_result : $@convention(thin) (@in_guaranteed Klass) -> ()
1585
+ %instance_1 = apply %getKlass() : $@convention(thin) () -> @owned Klass
1586
+ %src = alloc_stack $Klass
1587
+ store %instance_1 to [init] %src : $*Klass
1588
+ apply %user(%src) : $@convention(thin) (@in_guaranteed Klass) -> ()
1589
+ %tmp = alloc_stack $Klass
1590
+ copy_addr [take] %src to [init] %tmp : $*Klass
1591
+ %instance_2 = load [copy] %tmp : $*Klass
1592
+ destroy_addr %tmp : $*Klass
1593
+ dealloc_stack %tmp : $*Klass
1594
+ dealloc_stack %src : $*Klass
1595
+ return %instance_2 : $Klass
1596
+ }
1597
+
1598
+ // CHECK-LABEL: sil [ossa] @take_from_original_copy_addr__final_use_copy_addr_copy : {{.*}} {
1599
+ // CHECK: {{bb[0-9]+}}([[OUT:%[^,]+]] : $*Klass):
1600
+ // CHECK: [[GET:%[^,]+]] = function_ref @getKlass
1601
+ // CHECK: [[USER:%[^,]+]] = function_ref @inguaranteed_user_without_result
1602
+ // CHECK: [[INSTANCE:%[^,]+]] = apply [[GET]]()
1603
+ // CHECK: [[SRC:%[^,]+]] = alloc_stack $Klass
1604
+ // CHECK: store [[INSTANCE]] to [init] [[SRC]]
1605
+ // CHECK: apply [[USER]]([[SRC]])
1606
+ // CHECK: copy_addr [[SRC]] to [init] [[OUT]]
1607
+ // CHECK: destroy_addr [[SRC]]
1608
+ // CHECK: dealloc_stack [[SRC]]
1609
+ // CHECK-LABEL: } // end sil function 'take_from_original_copy_addr__final_use_copy_addr_copy'
1610
+ sil [ossa] @take_from_original_copy_addr__final_use_copy_addr_copy : $() -> @out Klass {
1611
+ entry(%out : $*Klass):
1612
+ %getKlass = function_ref @getKlass : $@convention(thin) () -> @owned Klass
1613
+ %user = function_ref @inguaranteed_user_without_result : $@convention(thin) (@in_guaranteed Klass) -> ()
1614
+ %instance_1 = apply %getKlass() : $@convention(thin) () -> @owned Klass
1615
+ %src = alloc_stack $Klass
1616
+ store %instance_1 to [init] %src : $*Klass
1617
+ apply %user(%src) : $@convention(thin) (@in_guaranteed Klass) -> ()
1618
+ %tmp = alloc_stack $Klass
1619
+ copy_addr [take] %src to [init] %tmp : $*Klass
1620
+ copy_addr %tmp to [init] %out : $*Klass
1621
+ destroy_addr %tmp : $*Klass
1622
+ dealloc_stack %tmp : $*Klass
1623
+ dealloc_stack %src : $*Klass
1624
+ %retval = tuple ()
1625
+ return %retval : $()
1626
+ }
1627
+
1509
1628
// This does not get optimized correctly because of the conservative treatment of load_borrow/end_borrow in MemBehavior
1510
1629
// CHECK-LABEL: sil [ossa] @test_temprvoborrowboundary1 :
1511
1630
// CHECK: copy_addr
0 commit comments