Skip to content

Commit 9996ac4

Browse files
committed
[OSSACanOwned] Extend all lifetimes to dead-ends.
Uses of borrows may occur between the borrow and a dead-end regardless of lexicality, so always extend lifetimes to dead-ends.
1 parent 3a72221 commit 9996ac4

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ class CanonicalizeOSSALifetime final {
368368
currentDef = def;
369369
currentLexicalLifetimeEnds = lexicalLifetimeEnds;
370370

371-
if (maximizeLifetime || respectsDeinitBarriers()) {
372-
liveness->initializeDiscoveredBlocks(&discoveredBlocks);
373-
}
371+
liveness->initializeDiscoveredBlocks(&discoveredBlocks);
374372
liveness->initializeDef(getCurrentDef());
375373
}
376374

lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,8 @@ bool CanonicalizeOSSALifetime::computeLiveness() {
13561356
clear();
13571357
return false;
13581358
}
1359+
extendLivenessToDeadEnds();
13591360
if (respectsDeinitBarriers()) {
1360-
extendLivenessToDeadEnds();
13611361
extendLivenessToDeinitBarriers();
13621362
}
13631363
if (accessBlockAnalysis) {

test/SILOptimizer/assemblyvision_remark/chacha.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func checkResult(_ plaintext: [UInt8]) {
2828

2929
@_semantics("optremark.sil-assembly-vision-remark-gen")
3030
public func run_ChaCha(_ N: Int) {
31-
let key = Array(repeating: UInt8(1), count: 32) // expected-remark {{release of type '}}
32-
let nonce = Array(repeating: UInt8(2), count: 12) // expected-remark {{release of type '}}
31+
let key = Array(repeating: UInt8(1), count: 32) // expected-note {{of 'key}}
32+
let nonce = Array(repeating: UInt8(2), count: 12) // expected-note {{of 'nonce}}
3333

3434
var checkedtext = Array(repeating: UInt8(0), count: 1024) // expected-note {{of 'checkedtext}}
3535
ChaCha20.encrypt(bytes: &checkedtext, key: key, nonce: nonce)
@@ -44,3 +44,5 @@ public func run_ChaCha(_ N: Int) {
4444
}
4545
} // expected-remark {{release of type '}}
4646
// expected-remark @-1 {{release of type '}}
47+
// expected-remark @-2 {{release of type '}}
48+
// expected-remark @-3 {{release of type '}}

test/SILOptimizer/canonicalize_ossa_lifetime_unit.sil

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,33 @@ die:
885885
unreachable
886886
}
887887

888+
// CHECK-LABEL: begin running test {{.*}} on consume_copy_before_use_in_dead_end_2
889+
// CHECK-LABEL: sil [ossa] @consume_copy_before_use_in_dead_end_2 : {{.*}} {
890+
// CHECK-NOT: destroy_value [dead_end]
891+
// CHECK-LABEL: } // end sil function 'consume_copy_before_use_in_dead_end_2'
892+
// CHECK-LABEL: end running test {{.*}} on consume_copy_before_use_in_dead_end_2
893+
sil [ossa] @consume_copy_before_use_in_dead_end_2 : $@convention(thin) (@owned C) -> () {
894+
entry(%c : @owned $C):
895+
cond_br undef, exit, die
896+
897+
exit:
898+
destroy_value %c
899+
%retval = tuple ()
900+
return %retval
901+
902+
die:
903+
%move = move_value %c
904+
%copy = copy_value %move
905+
specify_test "canonicalize_ossa_lifetime true false true %move"
906+
apply undef(%move) : $@convention(thin) (@owned C) -> ()
907+
%addr = alloc_stack $C
908+
%token = store_borrow %copy to %addr
909+
apply undef() : $@convention(thin) () -> ()
910+
%reload = load_borrow %token
911+
apply undef(%reload) : $@convention(thin) (@guaranteed C) -> ()
912+
unreachable
913+
}
914+
888915
// The destroy of a value must not be hoisted over a destroy of a copy of a
889916
// partial_apply [on_stack] which captures the value.
890917
// CHECK-LABEL: begin running test {{.*}} on destroy_after_pa_copy_destroy

test/SILOptimizer/copy_propagation.sil

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,13 @@ bb4:
838838

839839
// Test a dead begin_borrow (with no scope ending uses). Make sure
840840
// copy-propagation doesn't end the lifetime before the dead borrow.
841+
// (Indeed, it doesn't end the lifetime at all.)
841842
//
842843
// CHECK-LABEL: sil hidden [ossa] @testDeadBorrow : {{.*}} {
843-
// CHECK: bb0:
844-
// CHECK-NOT: copy_value
845-
// CHECK: begin_borrow
846-
// CHECK: destroy_value
847-
// CHECK: unreachable
844+
// CHECK: bb0:
845+
// CHECK-NOT: copy_value
846+
// CHECK: begin_borrow
847+
// CHECK-NEXT: unreachable
848848
// CHECK-LABEL: } // end sil function 'testDeadBorrow'
849849
sil hidden [ossa] @testDeadBorrow : $@convention(thin) () -> () {
850850
bb0:

0 commit comments

Comments
 (0)