Skip to content

Commit 14c2caa

Browse files
committed
[Test] Adapted copy_propagation_borrow to shrink.
1 parent 3e8948e commit 14c2caa

File tree

1 file changed

+12
-39
lines changed

1 file changed

+12
-39
lines changed

test/SILOptimizer/copy_propagation_borrow.sil

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,8 @@ bb3:
219219
//
220220
// CHECK-LABEL: sil [ossa] @testLocalBorrowPostDomDestroy : $@convention(thin) (@owned C) -> () {
221221
// CHECK: [[OUTERCOPY:%.*]] = copy_value %0 : $C
222-
// CHECK-NEXT: [[BORROW:%.*]] = begin_borrow %0 : $C
223222
// CHECK-NOT: copy_value
224-
// CHECK: end_borrow [[BORROW]] : $C
225-
// CHECK-NEXT: cond_br undef, bb1, bb2
223+
// CHECK: cond_br undef, bb1, bb2
226224
// CHECK: bb1:
227225
// CHECK-NEXT: [[COPY:%.*]] = copy_value [[OUTERCOPY]] : $C
228226
// CHECK-NEXT: apply %{{.*}}([[COPY]]) : $@convention(thin) (@owned C) -> ()
@@ -262,10 +260,8 @@ bb3:
262260
//
263261
// CHECK-LABEL: sil [ossa] @testLocalBorrowNoPostDomDestroy : $@convention(thin) (@owned C) -> () {
264262
// CHECK: [[OUTERCOPY:%.*]] = copy_value %0 : $C
265-
// CHECK-NEXT: [[BORROW:%.*]] = begin_borrow %0 : $C
266263
// CHECK-NOT: copy_value
267-
// CHECK: end_borrow [[BORROW]] : $C
268-
// CHECK-NEXT: cond_br undef, bb1, bb2
264+
// CHECK: cond_br undef, bb1, bb2
269265
// CHECK: bb1:
270266
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@guaranteed C) -> ()
271267
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@owned C) -> ()
@@ -305,10 +301,8 @@ bb3:
305301

306302
// CHECK-LABEL: sil [ossa] @testLocalBorrowDoubleConsume : $@convention(thin) (@owned C) -> () {
307303
// CHECK: [[OUTERCOPY:%.*]] = copy_value %0 : $C
308-
// CHECK-NEXT: begin_borrow %0 : $C
309304
// CHECK-NOT: copy
310-
// CHECK: end_borrow
311-
// CHECK-NEXT: cond_br undef, bb1, bb2
305+
// CHECK: cond_br undef, bb1, bb2
312306
// CHECK: bb1:
313307
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@guaranteed C) -> ()
314308
// CHECK-NEXT: [[ARGCOPY:%.*]] = copy_value [[OUTERCOPY]] : $C
@@ -398,11 +392,9 @@ bb3:
398392
// CHECK: [[ALLOC:%.*]] = alloc_ref $C
399393
// CHECK-NEXT: [[B1:%.*]] = begin_borrow [[ALLOC]]
400394
// CHECK-NOT: copy
401-
// CHECK: [[B2:%.*]] = begin_borrow [[ALLOC]]
402395
// CHECK-NOT: copy
403396
// CHECK: end_borrow [[B1]] : $C
404-
// CHECK-NEXT: apply %0([[B2]]) : $@convention(thin) (@guaranteed C) -> ()
405-
// CHECK-NEXT: end_borrow [[B2]] : $C
397+
// CHECK: apply %0([[ALLOC]]) : $@convention(thin) (@guaranteed C) -> ()
406398
// CHECK-NEXT: return [[ALLOC]] : $C
407399
// CHECK-LABEL: } // end sil function 'testInterleavedBorrow'
408400
sil [ossa] @testInterleavedBorrow : $@convention(thin) () -> @owned C {
@@ -429,17 +421,12 @@ bb0:
429421
//
430422
// CHECK-LABEL: sil [ossa] @testInterleavedBorrowCrossBlock : $@convention(thin) () -> @owned C {
431423
// CHECK: [[ALLOC:%.*]] = alloc_ref $C
432-
// CHECK: [[B1:%.*]] = begin_borrow [[ALLOC]]
433-
// CHECK: apply %{{.*}}([[B1]]) : $@convention(thin) (@guaranteed C) -> ()
434-
// CHECK-NEXT: [[B2:%.*]] = begin_borrow [[ALLOC]]
435-
// CHECK-NEXT: end_borrow [[B1]] : $C
424+
// CHECK: apply %{{.*}}([[ALLOC]]) : $@convention(thin) (@guaranteed C) -> ()
436425
// CHECK-NEXT: cond_br undef, bb1, bb2
437426
// CHECK: bb1:
438-
// CHECK: apply %{{.*}}([[B2]]) : $@convention(thin) (@guaranteed C) -> ()
439-
// CHECK-NEXT: end_borrow [[B2]] : $C
427+
// CHECK: apply %{{.*}}([[ALLOC]]) : $@convention(thin) (@guaranteed C) -> ()
440428
// CHECK-NEXT: br bb3
441429
// CHECK: bb2:
442-
// CHECK-NEXT: end_borrow [[B2]] : $C
443430
// CHECK-NEXT: br bb3
444431
// CHECK: bb3:
445432
// CHECK-NEXT: return [[ALLOC]] : $C
@@ -685,10 +672,8 @@ bb3(%borrowphi : @guaranteed $C):
685672
// CHECK-LABEL: sil [ossa] @testNestedReborrowOutsideUse : $@convention(thin) () -> () {
686673
// CHECK: [[ALLOC:%.*]] = alloc_ref $C
687674
// CHECK: bb3([[BORROWPHI:%.*]] : @guaranteed $C):
688-
// CHECK-NEXT: begin_borrow [[BORROWPHI]] : $C
689675
// CHECK-NOT: copy
690-
// CHECK: end_borrow
691-
// CHECK-NEXT: end_borrow
676+
// CHECK: end_borrow [[BORROWPHI]]
692677
// CHECK-NEXT: destroy_value [[ALLOC]] : $C
693678
// CHECK-LABEL: } // end sil function 'testNestedReborrowOutsideUse'
694679
sil [ossa] @testNestedReborrowOutsideUse : $@convention(thin) () -> () {
@@ -763,23 +748,15 @@ bb3(%borrow3 : @guaranteed $C, %copy3 : @owned $C):
763748

764749
// Test conversion from struct_extract to destructure.
765750
//
766-
// TODO: Remove the inner borrow scope becaues its outer value is
767-
// already guaranteed and it only has instantaneous uses. Then shrink
768-
// the outer borrow scope, hoist the destructure, rewrite the destroy
769-
// to be of the destructured valud, and finally also remove the dead
770-
// outer borrow scope. See rdar://79149830 (Shrink borrow scopes in
771-
// CanonicalizeBorrowScope)
772-
//
773751
// CHECK-LABEL: sil [ossa] @testDestructureConversion : $@convention(thin) (@owned Wrapper) -> () {
774752
// CHECK: bb0(%0 : @owned $Wrapper):
775753
// CHECK-NOT: copy
776-
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Wrapper
777-
// CHECK: [[SPLIT:%.*]] = destructure_struct [[BORROW]] : $Wrapper
754+
// CHECK: [[SPLIT:%.*]] = destructure_struct %0 : $Wrapper
778755
// CHECK: [[BORROWINNER:%.*]] = begin_borrow [[SPLIT]] : $HasObjectAndInt
779756
// CHECK: debug_value [[BORROWINNER]] : $HasObjectAndInt, let, name "self", argno 1
780757
// CHECK: struct_extract [[BORROWINNER]] : $HasObjectAndInt, #HasObjectAndInt.value
781758
// CHECK: end_borrow [[BORROWINNER]] : $HasObjectAndInt
782-
// CHECK: destroy_value %0 : $Wrapper
759+
// CHECK: destroy_value [[SPLIT]] : $HasObjectAndInt
783760
// CHECK-LABEL: } // end sil function 'testDestructureConversion'
784761
sil [ossa] @testDestructureConversion : $@convention(thin) (@owned Wrapper) -> () {
785762
bb0(%0 : @owned $Wrapper):
@@ -973,17 +950,13 @@ bb0(%0 : @owned $HasObjectAndInt):
973950

974951
// Test removing copies within an outer borrow scope with no outer uses.
975952
//
976-
// TODO: The redundant borrow scope should be removed by a SemanticARC pass.
977-
//
978953
// CHECK-LABEL: sil [ossa] @testBorrowCopy : $@convention(thin) (@guaranteed C) -> Int64 {
979954
// CHECK: bb0(%0 : @guaranteed $C):
980955
// CHECK-NEXT: %1 = begin_borrow %0 : $C
981-
// CHECK-NEXT: %2 = begin_borrow %1 : $C
982-
// CHECK-NEXT: %3 = ref_element_addr %2 : $C, #C.a
983-
// CHECK-NEXT: %4 = load [trivial] %3 : $*Int64
984-
// CHECK-NEXT: end_borrow %2 : $C
956+
// CHECK-NEXT: %2 = ref_element_addr %1 : $C, #C.a
957+
// CHECK-NEXT: %3 = load [trivial] %2 : $*Int64
985958
// CHECK-NEXT: end_borrow %1 : $C
986-
// CHECK-NEXT: return %4 : $Int64
959+
// CHECK-NEXT: return %3 : $Int64
987960
// CHECK-LABEL: } // end sil function 'testBorrowCopy'
988961
sil [ossa] @testBorrowCopy : $@convention(thin) (@guaranteed C) -> Int64 {
989962
bb0(%0 : @guaranteed $C):

0 commit comments

Comments
 (0)