Skip to content

Commit

Permalink
Fix copy_value to have 'None' side-effects.
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
atrick committed Jun 14, 2021
1 parent b001b0b commit 851bfeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion include/swift/SIL/SILNodes.def
Expand Up @@ -582,8 +582,10 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
SINGLE_VALUE_INST(CopyBlockWithoutEscapingInst, copy_block_without_escaping,
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
// A copy_value's retain semantics are fully encapsulated in OSSA
// invariants. It has no side effects relative to other OSSA values.
SINGLE_VALUE_INST(CopyValueInst, copy_value,
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
SingleValueInstruction, None, DoesNotRelease)
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
SINGLE_VALUE_INST(StrongCopy##Name##ValueInst, strong_copy_##name##_value, \
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
Expand Down
12 changes: 6 additions & 6 deletions test/SILOptimizer/cse_apply_ossa.sil
Expand Up @@ -122,11 +122,11 @@ bb0(%0 : $Int64):
return %14 : $Int64
}

// CHECK-LABEL: sil [ossa] @dont_cse_retain_only_apply :
// CHECK: %{{[0-9]+}} = apply
// CHECK: %{{[0-9]+}} = apply
// CHECK-LABEL:} // end sil function 'dont_cse_retain_only_apply'
sil [ossa] @dont_cse_retain_only_apply : $@convention(thin) () -> () {
// CHECK-LABEL: sil [ossa] @cse_retain_only_apply :
// CHECK: apply
// CHECK-NOT: apply
// CHECK-LABEL:} // end sil function 'cse_retain_only_apply'
sil [ossa] @cse_retain_only_apply : $@convention(thin) () -> () {
bb0:
%f = function_ref @retain_only : $@convention(thin) () -> @owned XX
%a1 = apply %f() : $@convention(thin) () -> @owned XX
Expand Down Expand Up @@ -169,7 +169,7 @@ bb0(%0 : @guaranteed $Klass):

// CHECK-LABEL: sil [ossa] @apply_nontrivial_test2 :
// CHECK: apply
// CHECK: apply
// CHECK-NOT: apply
// CHECK-LABEL:} // end sil function 'apply_nontrivial_test2'
sil [ossa] @apply_nontrivial_test2 : $@convention(thin) (@guaranteed Klass) -> () {
bb0(%0 : @guaranteed $Klass):
Expand Down
8 changes: 6 additions & 2 deletions test/SILOptimizer/sil_combine_ossa.sil
Expand Up @@ -772,14 +772,18 @@ sil [ossa] @unbalanced_closure : $@convention(thin) (@guaranteed B) -> ()
// CHECK-NOT: partial_apply
// Check that the arguments of the closure are released after its last use
// CHECK-NEXT: destroy_value %0 : $B
// CHECK-NEXT: unreachable
// CHECK-NEXT: tuple
// CHECK-NEXT: return
// CHECK: } // end sil function 'partial_apply_unbalanced_retain_release'
sil [ossa] @partial_apply_unbalanced_retain_release : $@convention(thin) (@owned B) -> () {
bb0(%0 : @owned $B):
%1 = function_ref @unbalanced_closure : $@convention(thin) (@guaranteed B) -> ()
%2 = partial_apply %1(%0) : $@convention(thin) (@guaranteed B) -> ()
%2a = copy_value %2 : $@callee_owned () -> ()
unreachable
destroy_value %2 : $@callee_owned () -> ()
destroy_value %2a : $@callee_owned () -> ()
%99 = tuple ()
return %99 : $()
}

class C1 {}
Expand Down

0 comments on commit 851bfeb

Please sign in to comment.