Skip to content

Commit 535a1b5

Browse files
authored
Merge pull request #37756 from atrick/fix-copy-sideeffect
Fix copy_value to have 'None' side-effects.
2 parents 23fb398 + 988ff18 commit 535a1b5

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/swift/SIL/SILNodes.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,10 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
574574
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
575575
SINGLE_VALUE_INST(CopyBlockWithoutEscapingInst, copy_block_without_escaping,
576576
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
577+
// A copy_value's retain semantics are fully encapsulated in OSSA
578+
// invariants. It has no side effects relative to other OSSA values.
577579
BRIDGED_SINGLE_VALUE_INST(CopyValueInst, copy_value,
578-
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
580+
SingleValueInstruction, None, DoesNotRelease)
579581
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
580582
SINGLE_VALUE_INST(StrongCopy##Name##ValueInst, strong_copy_##name##_value, \
581583
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)

test/SILOptimizer/cse_apply_ossa.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ bb0(%0 : $Int64):
122122
return %14 : $Int64
123123
}
124124

125-
// CHECK-LABEL: sil [ossa] @dont_cse_retain_only_apply :
126-
// CHECK: %{{[0-9]+}} = apply
127-
// CHECK: %{{[0-9]+}} = apply
128-
// CHECK-LABEL:} // end sil function 'dont_cse_retain_only_apply'
129-
sil [ossa] @dont_cse_retain_only_apply : $@convention(thin) () -> () {
125+
// CHECK-LABEL: sil [ossa] @cse_retain_only_apply :
126+
// CHECK: apply
127+
// CHECK-NOT: apply
128+
// CHECK-LABEL:} // end sil function 'cse_retain_only_apply'
129+
sil [ossa] @cse_retain_only_apply : $@convention(thin) () -> () {
130130
bb0:
131131
%f = function_ref @retain_only : $@convention(thin) () -> @owned XX
132132
%a1 = apply %f() : $@convention(thin) () -> @owned XX
@@ -169,7 +169,7 @@ bb0(%0 : @guaranteed $Klass):
169169

170170
// CHECK-LABEL: sil [ossa] @apply_nontrivial_test2 :
171171
// CHECK: apply
172-
// CHECK: apply
172+
// CHECK-NOT: apply
173173
// CHECK-LABEL:} // end sil function 'apply_nontrivial_test2'
174174
sil [ossa] @apply_nontrivial_test2 : $@convention(thin) (@guaranteed Klass) -> () {
175175
bb0(%0 : @guaranteed $Klass):

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,18 @@ sil [ossa] @unbalanced_closure : $@convention(thin) (@guaranteed B) -> ()
772772
// CHECK-NOT: partial_apply
773773
// Check that the arguments of the closure are released after its last use
774774
// CHECK-NEXT: destroy_value %0 : $B
775-
// CHECK-NEXT: unreachable
775+
// CHECK-NEXT: tuple
776+
// CHECK-NEXT: return
776777
// CHECK: } // end sil function 'partial_apply_unbalanced_retain_release'
777778
sil [ossa] @partial_apply_unbalanced_retain_release : $@convention(thin) (@owned B) -> () {
778779
bb0(%0 : @owned $B):
779780
%1 = function_ref @unbalanced_closure : $@convention(thin) (@guaranteed B) -> ()
780781
%2 = partial_apply %1(%0) : $@convention(thin) (@guaranteed B) -> ()
781782
%2a = copy_value %2 : $@callee_owned () -> ()
782-
unreachable
783+
destroy_value %2 : $@callee_owned () -> ()
784+
destroy_value %2a : $@callee_owned () -> ()
785+
%99 = tuple ()
786+
return %99 : $()
783787
}
784788

785789
class C1 {}

0 commit comments

Comments
 (0)