@@ -1554,6 +1554,53 @@ bb0(%0 : @guaranteed $T, %1 : $@thick U.Type):
1554
1554
return %6 : $U
1555
1555
}
1556
1556
1557
+ // There's only one use and it's a copy, just rewrite it as a load [copy].
1558
+ // CHECK-LABEL: sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable :
1559
+ // CHECK: {{bb[0-9]+}}([[ADDR_IN:%[^,]+]] : $*T):
1560
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $T
1561
+ // CHECK: copy_addr [[ADDR_IN]] to [init] [[STACK]]
1562
+ // CHECK: [[STACK_AS_CLASS:%[^,]+]] = unchecked_addr_cast [[STACK]] : $*T to $*Klass
1563
+ // CHECK: [[KLASS:%[^,]+]] = load [copy] [[STACK_AS_CLASS]]
1564
+ // CHECK: destroy_addr [[STACK]]
1565
+ // CHECK: dealloc_stack [[STACK]]
1566
+ // CHECK: return [[KLASS]]
1567
+ // CHECK-LABEL: } // end sil function 'test_unchecked_bitwise_cast_to_loadable'
1568
+ sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable : $@convention(thin) <T> (@in_guaranteed T) -> @owned Klass {
1569
+ bb0(%instance : @guaranteed $T):
1570
+ %copy = copy_value %instance : $T
1571
+ %unowned_klass = unchecked_bitwise_cast %copy : $T to $Klass
1572
+ %klass = copy_value %unowned_klass : $Klass
1573
+ destroy_value %copy : $T
1574
+ return %klass : $Klass
1575
+ }
1576
+
1577
+ // There is more than one use of the unchecked_addr_cast. The value should be
1578
+ // load_borrow'd and uses of the original should be uses of that load.
1579
+ // CHECK-LABEL: sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable_multiuse : {{.*}} {
1580
+ // CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : $*T):
1581
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $T
1582
+ // CHECK: copy_addr [[INSTANCE]] to [init] [[STACK]]
1583
+ // CHECK: [[STACK_AS_CLASS:%[^,]+]] = unchecked_addr_cast [[STACK]] : $*T to $*Klass
1584
+ // CHECK: [[BORROWED_KLASS:%[^,]+]] = load_borrow [[STACK_AS_CLASS]]
1585
+ // CHECK: [[KLASS_TO_RETURN:%[^,]+]] = copy_value [[BORROWED_KLASS]]
1586
+ // CHECK: [[KLASS_TO_DESTROY:%[^,]+]] = copy_value [[BORROWED_KLASS]]
1587
+ // CHECK: end_borrow [[BORROWED_KLASS]]
1588
+ // CHECK: destroy_value [[KLASS_TO_DESTROY]]
1589
+ // CHECK: destroy_addr [[STACK]]
1590
+ // CHECK: dealloc_stack [[STACK]]
1591
+ // CHECK: return [[KLASS_TO_RETURN]]
1592
+ // CHECK-LABEL: } // end sil function 'test_unchecked_bitwise_cast_to_loadable_multiuse'
1593
+ sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable_multiuse : $@convention(thin) <T> (@in_guaranteed T) -> @owned Klass {
1594
+ bb0(%instance : @guaranteed $T):
1595
+ %copy = copy_value %instance : $T
1596
+ %unowned_klass = unchecked_bitwise_cast %copy : $T to $Klass
1597
+ %klass = copy_value %unowned_klass : $Klass
1598
+ %klass2 = copy_value %unowned_klass : $Klass
1599
+ destroy_value %klass2 : $Klass
1600
+ destroy_value %copy : $T
1601
+ return %klass : $Klass
1602
+ }
1603
+
1557
1604
// CHECK-LABEL: sil hidden [ossa] @test_unconditional_checked_cast1 : $@convention(thin) <T> (Builtin.Int64) -> @out T {
1558
1605
// CHECK: bb0(%0 : $*T, %1 : $Builtin.Int64):
1559
1606
// CHECK: [[INT:%.*]] = alloc_stack $Builtin.Int64
0 commit comments