@@ -1340,6 +1340,23 @@ exit_error(%47 : @owned $any Error):
1340
1340
throw %47 : $any Error
1341
1341
}
1342
1342
1343
+ // CHECK-LABEL: sil [ossa] @selecteroo : $@convention(thin) <T> () -> () {
1344
+ // CHECK: [[ADDR:%[^,]+]] = alloc_stack $Optional<T>
1345
+ // CHECK: apply undef<T>([[ADDR]]) : $@convention(thin) <τ_0_0> () -> @out Optional<τ_0_0>
1346
+ // CHECK: select_enum_addr [[ADDR]] : $*Optional<T>, case #Optional.some!enumelt: {{%[^,]+}}, default {{%[^,]+}} : $Builtin.Int1
1347
+ // CHECK: dealloc_stack [[ADDR]] : $*Optional<T>
1348
+ // CHECK-LABEL: } // end sil function 'selecteroo'
1349
+ sil [ossa] @selecteroo : $@convention(thin) <T> () -> () {
1350
+ bb0:
1351
+ %11 = apply undef<T>() : $@convention(thin) <τ_0_0> () -> @out Optional<τ_0_0>
1352
+ %12 = integer_literal $Builtin.Int1, -1
1353
+ %13 = integer_literal $Builtin.Int1, 0
1354
+ %14 = select_enum %11 : $Optional<T>, case #Optional.some!enumelt: %12, default %13 : $Builtin.Int1
1355
+ destroy_value %11 : $Optional<T>
1356
+ %retval = tuple ()
1357
+ return %retval : $()
1358
+ } // end sil function '$ss17FixedWidthIntegerPsEyxSgSScfC'
1359
+
1343
1360
sil hidden [ossa] @testBeginApplyDeadYield : $@convention(thin) <T> (@guaranteed TestGeneric<T>) -> () {
1344
1361
bb0(%0 : @guaranteed $TestGeneric<T>):
1345
1362
%2 = class_method %0 : $TestGeneric<T>, #TestGeneric.borrowedGeneric!read : <T> (TestGeneric<T>) -> () -> (), $@yield_once @convention(method) <τ_0_0> (@guaranteed TestGeneric<τ_0_0>) -> @yields @in_guaranteed τ_0_0
@@ -1554,6 +1571,53 @@ bb0(%0 : @guaranteed $T, %1 : $@thick U.Type):
1554
1571
return %6 : $U
1555
1572
}
1556
1573
1574
+ // There's only one use and it's a copy, just rewrite it as a load [copy].
1575
+ // CHECK-LABEL: sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable :
1576
+ // CHECK: {{bb[0-9]+}}([[ADDR_IN:%[^,]+]] : $*T):
1577
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $T
1578
+ // CHECK: copy_addr [[ADDR_IN]] to [init] [[STACK]]
1579
+ // CHECK: [[STACK_AS_CLASS:%[^,]+]] = unchecked_addr_cast [[STACK]] : $*T to $*Klass
1580
+ // CHECK: [[KLASS:%[^,]+]] = load [copy] [[STACK_AS_CLASS]]
1581
+ // CHECK: destroy_addr [[STACK]]
1582
+ // CHECK: dealloc_stack [[STACK]]
1583
+ // CHECK: return [[KLASS]]
1584
+ // CHECK-LABEL: } // end sil function 'test_unchecked_bitwise_cast_to_loadable'
1585
+ sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable : $@convention(thin) <T> (@in_guaranteed T) -> @owned Klass {
1586
+ bb0(%instance : @guaranteed $T):
1587
+ %copy = copy_value %instance : $T
1588
+ %unowned_klass = unchecked_bitwise_cast %copy : $T to $Klass
1589
+ %klass = copy_value %unowned_klass : $Klass
1590
+ destroy_value %copy : $T
1591
+ return %klass : $Klass
1592
+ }
1593
+
1594
+ // There is more than one use of the unchecked_addr_cast. The value should be
1595
+ // load_borrow'd and uses of the original should be uses of that load.
1596
+ // CHECK-LABEL: sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable_multiuse : {{.*}} {
1597
+ // CHECK: {{bb[0-9]+}}([[INSTANCE:%[^,]+]] : $*T):
1598
+ // CHECK: [[STACK:%[^,]+]] = alloc_stack $T
1599
+ // CHECK: copy_addr [[INSTANCE]] to [init] [[STACK]]
1600
+ // CHECK: [[STACK_AS_CLASS:%[^,]+]] = unchecked_addr_cast [[STACK]] : $*T to $*Klass
1601
+ // CHECK: [[BORROWED_KLASS:%[^,]+]] = load_borrow [[STACK_AS_CLASS]]
1602
+ // CHECK: [[KLASS_TO_RETURN:%[^,]+]] = copy_value [[BORROWED_KLASS]]
1603
+ // CHECK: [[KLASS_TO_DESTROY:%[^,]+]] = copy_value [[BORROWED_KLASS]]
1604
+ // CHECK: end_borrow [[BORROWED_KLASS]]
1605
+ // CHECK: destroy_value [[KLASS_TO_DESTROY]]
1606
+ // CHECK: destroy_addr [[STACK]]
1607
+ // CHECK: dealloc_stack [[STACK]]
1608
+ // CHECK: return [[KLASS_TO_RETURN]]
1609
+ // CHECK-LABEL: } // end sil function 'test_unchecked_bitwise_cast_to_loadable_multiuse'
1610
+ sil hidden [ossa] @test_unchecked_bitwise_cast_to_loadable_multiuse : $@convention(thin) <T> (@in_guaranteed T) -> @owned Klass {
1611
+ bb0(%instance : @guaranteed $T):
1612
+ %copy = copy_value %instance : $T
1613
+ %unowned_klass = unchecked_bitwise_cast %copy : $T to $Klass
1614
+ %klass = copy_value %unowned_klass : $Klass
1615
+ %klass2 = copy_value %unowned_klass : $Klass
1616
+ destroy_value %klass2 : $Klass
1617
+ destroy_value %copy : $T
1618
+ return %klass : $Klass
1619
+ }
1620
+
1557
1621
// CHECK-LABEL: sil hidden [ossa] @test_unconditional_checked_cast1 : $@convention(thin) <T> (Builtin.Int64) -> @out T {
1558
1622
// CHECK: bb0(%0 : $*T, %1 : $Builtin.Int64):
1559
1623
// CHECK: [[INT:%.*]] = alloc_stack $Builtin.Int64
0 commit comments