Skip to content

Commit 851bfeb

Browse files
committed
Fix copy_value to have 'None' side-effects.
Copies can be moved as much as you like as long as OSSA is legal. This fixes some instruction deletion utilities for OSSA and any other utilities that check side effects. Copies are common. It also finally allows pure functions to be CSE'd!
1 parent b001b0b commit 851bfeb

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
@@ -582,8 +582,10 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
582582
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
583583
SINGLE_VALUE_INST(CopyBlockWithoutEscapingInst, copy_block_without_escaping,
584584
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
585+
// A copy_value's retain semantics are fully encapsulated in OSSA
586+
// invariants. It has no side effects relative to other OSSA values.
585587
SINGLE_VALUE_INST(CopyValueInst, copy_value,
586-
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
588+
SingleValueInstruction, None, DoesNotRelease)
587589
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
588590
SINGLE_VALUE_INST(StrongCopy##Name##ValueInst, strong_copy_##name##_value, \
589591
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)