@@ -142,9 +142,11 @@ bb0(%0 : @owned $Klass, %1 : @owned $Klass):
142
142
return %5 : $(Klass)
143
143
}
144
144
145
+ // mayIntroduceUnoptimizableCopies returns true because swift::areUsesWithinValueLifetime returns false
146
+ // since findOwnershipReferenceAggregate only looks through single operand forwarding instructions
145
147
// CHECK-LABEL: sil [ossa] @tuple_test2 :
146
148
// CHECK: tuple ({{%[0-9]+}} : $Klass, {{%[0-9]+}} : $Klass)
147
- // CHECK-NOT: tuple ({{%[0-9]+}} : $Klass, {{%[0-9]+}} : $Klass)
149
+ // TODO- CHECK-NOT: tuple ({{%[0-9]+}} : $Klass, {{%[0-9]+}} : $Klass)
148
150
// CHECK-LABEL: } // end sil function 'tuple_test2'
149
151
sil [ossa] @tuple_test2 : $@convention(thin) (@guaranteed Klass, @guaranteed Klass) -> @owned (Klass) {
150
152
bb0(%0 : @guaranteed $Klass, %1 : @guaranteed $Klass):
@@ -439,7 +441,7 @@ bb0(%0 : @guaranteed $(Klass, Klass)):
439
441
440
442
// CHECK-LABEL: sil [ossa] @struct_test2 :
441
443
// CHECK: struct $NonTrivialStruct
442
- // CHECK-NOT: struct $NonTrivialStruct
444
+ // TODO- CHECK-NOT: struct $NonTrivialStruct
443
445
// CHECK-LABEL: } // end sil function 'struct_test2'
444
446
sil [ossa] @struct_test2 : $@convention(thin) (@guaranteed Klass) -> @owned Klass {
445
447
bb0(%0 : @guaranteed $Klass):
@@ -454,7 +456,7 @@ bb0(%0 : @guaranteed $Klass):
454
456
455
457
// CHECK-LABEL: sil [ossa] @struct_test3 :
456
458
// CHECK: struct $NonTrivialStruct
457
- // CHECK-NOT: struct $NonTrivialStruct
459
+ // TODO- CHECK-NOT: struct $NonTrivialStruct
458
460
// CHECK-LABEL: } // end sil function 'struct_test3'
459
461
sil [ossa] @struct_test3 : $@convention(thin) (@guaranteed Klass) -> () {
460
462
bb0(%0 : @guaranteed $Klass):
@@ -504,7 +506,7 @@ bb0(%0 : @guaranteed $Klass):
504
506
505
507
// CHECK-LABEL: sil [ossa] @struct_extract_test1 :
506
508
// CHECK: struct_extract
507
- // CHECK-NOT: struct_extract
509
+ // TODO- CHECK-NOT: struct_extract
508
510
// CHECK-LABEL: } // end sil function 'struct_extract_test1'
509
511
sil [ossa] @struct_extract_test1 : $@convention(thin) (@owned NonTrivialStruct) -> @owned Klass {
510
512
bb0(%0 : @owned $NonTrivialStruct):
@@ -644,9 +646,9 @@ bb3(%borrow : @guaranteed $Klass):
644
646
// CHECK-LABEL: sil [ossa] @test_rauwfailsandthensucceeds :
645
647
// CHECK: bb0
646
648
// CHECK: struct_extract
647
- // CHECK: struct_extract
649
+ // TODO- CHECK: struct_extract
648
650
// CHECK: struct $_SliceBuffer
649
- // CHECK-NOT: struct $_SliceBuffer
651
+ // TODO- CHECK-NOT: struct $_SliceBuffer
650
652
// CHECK-LABEL: } // end sil function 'test_rauwfailsandthensucceeds'
651
653
sil [ossa] @test_rauwfailsandthensucceeds : $@convention(method) <Element> (UnsafeMutablePointer<Element>, @guaranteed _ContiguousArrayBuffer<Element>, Int, UInt) -> @owned _SliceBuffer<Element> {
652
654
bb0(%0 : $UnsafeMutablePointer<Element>, %1 : @guaranteed $_ContiguousArrayBuffer<Element>, %2 : $Int, %3 : $UInt):
@@ -1076,3 +1078,51 @@ bb0(%0 : $*Wrapper):
1076
1078
%18 = tuple ()
1077
1079
return %18
1078
1080
}
1081
+
1082
+ sil @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
1083
+
1084
+ // Both CopyPropagation and CopyToBorrow cannot eliminate the copy generated by
1085
+ // OSSA RAUW if we look through ownership instructions while CSE'ing
1086
+ // CHECK-LABEL: sil [ossa] @struct_copy_test1 :
1087
+ // CHECK: struct_extract
1088
+ // CHECK: struct_extract
1089
+ // CHECK-LABEL: } // end sil function 'struct_copy_test1'
1090
+ sil [ossa] @struct_copy_test1 : $@convention(thin) (@owned NonTrivialStruct) -> () {
1091
+ bb0(%0 : @owned $NonTrivialStruct):
1092
+ %f = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
1093
+ %b1 = begin_borrow %0
1094
+ %ex1 = struct_extract %b1, #NonTrivialStruct.val
1095
+ apply %f(%ex1) : $@convention(thin) (@guaranteed Klass) -> ()
1096
+ end_borrow %b1
1097
+ %b2 = begin_borrow %0
1098
+ %ex2 = struct_extract %b2, #NonTrivialStruct.val
1099
+ apply %f(%ex2) : $@convention(thin) (@guaranteed Klass) -> ()
1100
+ end_borrow %b2
1101
+ destroy_value %0 : $NonTrivialStruct
1102
+ %res = tuple ()
1103
+ return %res : $()
1104
+ }
1105
+
1106
+ // Both CopyPropagation and CopyToBorrow cannot eliminate the copy generated by
1107
+ // OSSA RAUW if we look through ownership instructions while CSE'ing
1108
+ // CHECK-LABEL: sil [ossa] @struct_copy_test2 :
1109
+ // CHECK: struct_extract
1110
+ // CHECK: struct_extract
1111
+ // CHECK-LABEL: } // end sil function 'struct_copy_test2'
1112
+ sil [ossa] @struct_copy_test2 : $@convention(thin) () -> () {
1113
+ bb0:
1114
+ %f1 = function_ref @get_nontrivialstruct : $@convention(thin) () -> @owned NonTrivialStruct
1115
+ %0 = apply %f1() : $@convention(thin) () -> @owned NonTrivialStruct
1116
+ %f2 = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> ()
1117
+ %b1 = begin_borrow %0
1118
+ %ex1 = struct_extract %b1, #NonTrivialStruct.val
1119
+ apply %f2(%ex1) : $@convention(thin) (@guaranteed Klass) -> ()
1120
+ end_borrow %b1
1121
+ %b2 = begin_borrow %0
1122
+ %ex2 = struct_extract %b2, #NonTrivialStruct.val
1123
+ apply %f2(%ex2) : $@convention(thin) (@guaranteed Klass) -> ()
1124
+ end_borrow %b2
1125
+ destroy_value %0 : $NonTrivialStruct
1126
+ %res = tuple ()
1127
+ return %res : $()
1128
+ }
0 commit comments