@@ -8,9 +8,12 @@ import Builtin
8
8
// Declarations //
9
9
//////////////////
10
10
11
+ enum MyNever {}
12
+
11
13
sil @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
12
14
sil @owned_user : $@convention(thin) (@owned Builtin.NativeObject) -> ()
13
15
sil @get_owned_obj : $@convention(thin) () -> @owned Builtin.NativeObject
16
+ sil @unreachable_guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
14
17
15
18
struct NativeObjectPair {
16
19
var obj1 : Builtin.NativeObject
@@ -775,4 +778,63 @@ bb0(%0 : $*NativeObjectPair):
775
778
destroy_addr %0 : $*NativeObjectPair
776
779
%9999 = tuple()
777
780
return %9999 : $()
778
- }
781
+ }
782
+
783
+ // Make sure we do not eliminate the copy_value below to ensure that all uses of
784
+ // %2 are before %2's end_borrow.
785
+ //
786
+ // We used to eliminate the copy_value and change %func to use %2.
787
+ //
788
+ // CHECK-LABEL: sil [ossa] @begin_borrow_used_by_postdominating_no_return_function : $@convention(thin) () -> MyNever {
789
+ // CHECK: copy_value
790
+ // CHECK: } // end sil function 'begin_borrow_used_by_postdominating_no_return_function'
791
+ sil [ossa] @begin_borrow_used_by_postdominating_no_return_function : $@convention(thin) () -> MyNever {
792
+ bb0:
793
+ %0 = function_ref @get_nativeobject_pair : $@convention(thin) () -> @owned NativeObjectPair
794
+ %1 = apply %0() : $@convention(thin) () -> @owned NativeObjectPair
795
+ %2 = begin_borrow %1 : $NativeObjectPair
796
+ %3 = struct_extract %2 : $NativeObjectPair, #NativeObjectPair.obj1
797
+ %4 = copy_value %3 : $Builtin.NativeObject
798
+ end_borrow %2 : $NativeObjectPair
799
+ %func = function_ref @unreachable_guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
800
+ apply %func(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
801
+ unreachable
802
+ }
803
+
804
+ // Make sure we do not eliminate the copy_value below to ensure that all uses of
805
+ // %2 are before %2's end_borrow.
806
+ //
807
+ // We used to eliminate the copy_value and change %func to use %2.
808
+ //
809
+ // CHECK-LABEL: sil [ossa] @load_borrow_used_by_postdominating_no_return_function : $@convention(thin) () -> MyNever {
810
+ // CHECK: copy_value
811
+ // CHECK: } // end sil function 'load_borrow_used_by_postdominating_no_return_function'
812
+ sil [ossa] @load_borrow_used_by_postdominating_no_return_function : $@convention(thin) () -> MyNever {
813
+ bb0:
814
+ %0 = function_ref @get_nativeobject_pair : $@convention(thin) () -> @owned NativeObjectPair
815
+ %1 = apply %0() : $@convention(thin) () -> @owned NativeObjectPair
816
+ %stackSlot = alloc_stack $NativeObjectPair
817
+ store %1 to [init] %stackSlot : $*NativeObjectPair
818
+ %2 = load_borrow %stackSlot : $*NativeObjectPair
819
+ %3 = struct_extract %2 : $NativeObjectPair, #NativeObjectPair.obj1
820
+ %4 = copy_value %3 : $Builtin.NativeObject
821
+ end_borrow %2 : $NativeObjectPair
822
+ %func = function_ref @unreachable_guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
823
+ apply %func(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
824
+ unreachable
825
+ }
826
+
827
+ // Make sure we do perform the optimization if our borrowed value is an
828
+ // argument.
829
+ //
830
+ // CHECK-LABEL: sil [ossa] @guaranteed_arg_used_by_postdominating_no_return_function : $@convention(thin) (@guaranteed NativeObjectPair) -> MyNever {
831
+ // CHECK-NOT: copy_value
832
+ // CHECK: } // end sil function 'guaranteed_arg_used_by_postdominating_no_return_function'
833
+ sil [ossa] @guaranteed_arg_used_by_postdominating_no_return_function : $@convention(thin) (@guaranteed NativeObjectPair) -> MyNever {
834
+ bb0(%0 : @guaranteed $NativeObjectPair):
835
+ %3 = struct_extract %0 : $NativeObjectPair, #NativeObjectPair.obj1
836
+ %4 = copy_value %3 : $Builtin.NativeObject
837
+ %func = function_ref @unreachable_guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
838
+ apply %func(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
839
+ unreachable
840
+ }
0 commit comments