Skip to content

Commit 880f15d

Browse files
committed
[Test] Adapted tests to CopyPropagation changes.
1 parent 4508571 commit 880f15d

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

test/SILOptimizer/copy_propagation_borrow.sil

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sil [ossa] @takeOwnedC : $@convention(thin) (@owned C) -> ()
2424
sil [ossa] @takeOwnedCTwice : $@convention(thin) (@owned C, @owned C) -> ()
2525
sil [ossa] @takeGuaranteedC : $@convention(thin) (@guaranteed C) -> ()
2626
sil [ossa] @accessRawP : $@convention(method) (Builtin.RawPointer) -> ()
27+
sil [ossa] @synchronization_point : $@convention(thin) () -> ()
2728

2829
struct NativeObjectPair {
2930
var obj1 : Builtin.NativeObject
@@ -329,7 +330,8 @@ bb0(%0 : @owned $C):
329330
%copy3 = copy_value %borrow : $C
330331
%copy4 = copy_value %borrow : $C
331332
// Force the borrow not to be eliminated early.
332-
%call0 = apply %fguaranteed(%borrow) : $@convention(thin) (@guaranteed C) -> ()
333+
%synchronization_point = function_ref @synchronization_point : $@convention(thin) () -> ()
334+
%synchronized = apply %synchronization_point() : $@convention(thin) () -> ()
333335
end_borrow %borrow : $C
334336
cond_br undef, bb1, bb2
335337
bb1:
@@ -421,7 +423,9 @@ bb0:
421423
//
422424
// CHECK-LABEL: sil [ossa] @testInterleavedBorrowCrossBlock : $@convention(thin) () -> @owned C {
423425
// CHECK: [[ALLOC:%.*]] = alloc_ref $C
424-
// CHECK: apply %{{.*}}([[ALLOC]]) : $@convention(thin) (@guaranteed C) -> ()
426+
// CHECK: [[B1:%.*]] = begin_borrow [[ALLOC]]
427+
// CHECK: apply %{{.*}}([[B1]]) : $@convention(thin) (@guaranteed C) -> ()
428+
// CHECK-NEXT: end_borrow [[B1]] : $C
425429
// CHECK-NEXT: cond_br undef, bb1, bb2
426430
// CHECK: bb1:
427431
// CHECK: apply %{{.*}}([[ALLOC]]) : $@convention(thin) (@guaranteed C) -> ()
@@ -507,8 +511,8 @@ bb3:
507511
// CHECK-LABEL: sil [ossa] @testEscapingForward : $@convention(method) (@guaranteed HasObject) -> () {
508512
// CHECK: begin_borrow %0 : $HasObject
509513
// CHECK: copy_value
510-
// CHECK: end_borrow
511514
// CHECK: destructure_struct
515+
// CHECK: end_borrow
512516
// CHECK: ref_to_unmanaged
513517
// CHECK: destroy_value
514518
// CHECK-LABEL: } // end sil function 'testEscapingForward'
@@ -748,15 +752,18 @@ bb3(%borrow3 : @guaranteed $C, %copy3 : @owned $C):
748752

749753
// Test conversion from struct_extract to destructure.
750754
//
755+
// TODO: The redundant borrow scope should be removed by a SemanticARC pass.
756+
//
751757
// CHECK-LABEL: sil [ossa] @testDestructureConversion : $@convention(thin) (@owned Wrapper) -> () {
752758
// CHECK: bb0(%0 : @owned $Wrapper):
753759
// CHECK-NOT: copy
754-
// CHECK: [[SPLIT:%.*]] = destructure_struct %0 : $Wrapper
760+
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Wrapper
761+
// CHECK: [[SPLIT:%.*]] = destructure_struct [[BORROW]] : $Wrapper
755762
// CHECK: [[BORROWINNER:%.*]] = begin_borrow [[SPLIT]] : $HasObjectAndInt
756763
// CHECK: debug_value [[BORROWINNER]] : $HasObjectAndInt, let, name "self", argno 1
757764
// CHECK: struct_extract [[BORROWINNER]] : $HasObjectAndInt, #HasObjectAndInt.value
758765
// CHECK: end_borrow [[BORROWINNER]] : $HasObjectAndInt
759-
// CHECK: destroy_value [[SPLIT]] : $HasObjectAndInt
766+
// CHECK: destroy_value %0 : $Wrapper
760767
// CHECK-LABEL: } // end sil function 'testDestructureConversion'
761768
sil [ossa] @testDestructureConversion : $@convention(thin) (@owned Wrapper) -> () {
762769
bb0(%0 : @owned $Wrapper):
@@ -950,13 +957,17 @@ bb0(%0 : @owned $HasObjectAndInt):
950957

951958
// Test removing copies within an outer borrow scope with no outer uses.
952959
//
960+
// TODO: The redundant borrow scope should be removed by a SemanticARC pass.
961+
//
953962
// CHECK-LABEL: sil [ossa] @testBorrowCopy : $@convention(thin) (@guaranteed C) -> Int64 {
954963
// CHECK: bb0(%0 : @guaranteed $C):
955964
// CHECK-NEXT: %1 = begin_borrow %0 : $C
956-
// CHECK-NEXT: %2 = ref_element_addr %1 : $C, #C.a
957-
// CHECK-NEXT: %3 = load [trivial] %2 : $*Int64
965+
// CHECK-NEXT: %2 = begin_borrow %1 : $C
966+
// CHECK-NEXT: %3 = ref_element_addr %2 : $C, #C.a
967+
// CHECK-NEXT: %4 = load [trivial] %3 : $*Int64
968+
// CHECK-NEXT: end_borrow %2 : $C
958969
// CHECK-NEXT: end_borrow %1 : $C
959-
// CHECK-NEXT: return %3 : $Int64
970+
// CHECK-NEXT: return %4 : $Int64
960971
// CHECK-LABEL: } // end sil function 'testBorrowCopy'
961972
sil [ossa] @testBorrowCopy : $@convention(thin) (@guaranteed C) -> Int64 {
962973
bb0(%0 : @guaranteed $C):

test/SILOptimizer/copy_propagation_opaque.sil

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,9 @@ bb0(%arg : @owned $T):
392392
}
393393

394394
// CHECK-TRACE-LABEL: *** CopyPropagation: testBorrowCopy
395-
// CHECK-TRACE: Outer copy [[OUTERCOPY:%.*]] = copy_value %0 : $T
396-
// CHECK-TRACE: Use of outer copy destroy_value
397-
// CHECK-TRACE: Deleting %{{.*}} = copy_value
398-
// CHECK-TRACE: Removing destroy_value [[OUTERCOPY]] : $T
399-
// CHECK-TRACE: Removing [[OUTERCOPY]] = copy_value %0 : $T
395+
// CHECK-TRACE: Canonicalizing: %0 = argument of bb0 : $T
396+
// CHECK-TRACE: Removing destroy_value [[REGISTER_1:%[^,]+]] : $T
397+
// CHECK-TRACE: Removing [[REGISTER_1]] = copy_value %0 : $T
400398
//
401399
// CHECK-LABEL: sil [ossa] @testBorrowCopy : $@convention(thin) <T> (@in T) -> () {
402400
// CHECK-LABEL: bb0(%0 : @owned $T):
@@ -416,11 +414,10 @@ bb0(%0 : @owned $T):
416414
}
417415

418416
// CHECK-TRACE-LABEL: *** CopyPropagation: testCopyBorrow
419-
// CHECK-TRACE-NOT: Removing
420417
//
421418
// CHECK-LABEL: sil [ossa] @testCopyBorrow : $@convention(thin) <T> (@in T) -> () {
422419
// CHECK: bb0(%0 : @owned $T):
423-
// CHECK-NEXT: destroy_value %0 : $T
420+
// CHECK: destroy_value %0 : $T
424421
// CHECK-NEXT: tuple
425422
// CHECK-NEXT: return
426423
// CHECK-LABEL: } // end sil function 'testCopyBorrow'

0 commit comments

Comments
 (0)