Skip to content

Commit 1aaae85

Browse files
authored
Merge pull request #82559 from eeckstein/fix-semantic-arc-opt-6.2
[6.2] SemanticARCOpts: don't ignore dead-end blocks in the liverange analysis
2 parents 92fd571 + 728f37a commit 1aaae85

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/SILOptimizer/SemanticARC/CopyValueOpts.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,9 @@ bool SemanticARCOptVisitor::tryPerformOwnedCopyValueOptimization(
805805
// Ok, we have an owned value. If we do not have any non-destroying consuming
806806
// uses, see if all of our uses (ignoring destroying uses) are within our
807807
// parent owned value's lifetime.
808-
LinearLifetimeChecker checker(&ctx.getDeadEndBlocks());
808+
// Note: we cannot optimistically ignore DeadEndBlocks - unlike for ownership
809+
// verification.
810+
LinearLifetimeChecker checker(nullptr);
809811
if (!checker.validateLifetime(originalValue, parentLifetimeEndingUses,
810812
allCopyUses))
811813
return false;

test/SILOptimizer/semantic-arc-opts-redundantcopyopts.sil

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-sil-opt -module-name Swift -enable-sil-verify-all -semantic-arc-opts -sil-semantic-arc-peepholes-redundant-copyvalue-elim %s | %FileCheck %s
2-
// REQUIRES: swift_stdlib_asserts
32

43
// NOTE: Some of our tests here depend on borrow elimination /not/ running!
54
// Please do not add it to clean up the IR like we did in
@@ -59,6 +58,11 @@ extension Klass : MyFakeAnyObject {
5958
sil [ossa] @guaranteed_klass_user : $@convention(thin) (@guaranteed Klass) -> ()
6059
sil [ossa] @guaranteed_fakeoptional_klass_user : $@convention(thin) (@guaranteed FakeOptional<Klass>) -> ()
6160
sil [ossa] @guaranteed_fakeoptional_classlet_user : $@convention(thin) (@guaranteed FakeOptional<ClassLet>) -> ()
61+
sil [ossa] @create_klass : $@convention(thin) () -> @owned Klass
62+
63+
struct ContainsKlass {
64+
var x: Klass
65+
}
6266

6367
struct MyInt {
6468
var value: Builtin.Int32
@@ -186,3 +190,17 @@ bb3:
186190
return %9999 : $()
187191
}
188192

193+
// CHECK-LABEL: sil [ossa] @copy_in_deadend_block :
194+
// CHECK: copy_value
195+
// CHECK: } // end sil function 'copy_in_deadend_block'
196+
sil [ossa] @copy_in_deadend_block : $@convention(thin) (@inout ContainsKlass) -> () {
197+
bb0(%1 : $*ContainsKlass):
198+
%129 = function_ref @create_klass : $@convention(thin) () -> @owned Klass
199+
%130 = apply %129() : $@convention(thin) () -> @owned Klass
200+
%131 = copy_value %130
201+
%133 = struct $ContainsKlass (%130)
202+
store %133 to [assign] %1
203+
fix_lifetime %131
204+
destroy_value %131
205+
unreachable
206+
}

0 commit comments

Comments
 (0)