Skip to content

Commit d55c169

Browse files
committed
[CopyPropagation] Destroy hoist -> canonicalize.
Replace usages of lexical destroy hoisting with owned value canonicalization now that the latter supports lexical values.
1 parent afca04d commit d55c169

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,9 @@ void CopyPropagation::run() {
503503
bool firstRun = true;
504504
// Run the sequence of utilities:
505505
// - ShrinkBorrowScope
506-
// - CanonicalizeOSSALifetime
506+
// - CanonicalizeOSSALifetime(borrowee)
507507
// - LexicalDestroyFolding
508+
// - CanonicalizeOSSALifetime(folded)
508509
// at least once and then until each stops making changes.
509510
while (true) {
510511
SmallVector<CopyValueInst *, 4> modifiedCopyValueInsts;
@@ -529,8 +530,7 @@ void CopyPropagation::run() {
529530
auto folded = foldDestroysOfCopiedLexicalBorrow(bbi, *domTree, deleter);
530531
if (!folded)
531532
break;
532-
auto hoisted =
533-
hoistDestroysOfOwnedLexicalValue(folded, *f, deleter, calleeAnalysis);
533+
auto hoisted = canonicalizer.canonicalizeValueLifetime(folded);
534534
// Keep running even if the new move's destroys can't be hoisted.
535535
(void)hoisted;
536536
eliminateRedundantMove(folded, deleter, defWorklist);
@@ -542,7 +542,7 @@ void CopyPropagation::run() {
542542
}
543543
for (auto *argument : f->getArguments()) {
544544
if (argument->getOwnershipKind() == OwnershipKind::Owned) {
545-
hoistDestroysOfOwnedLexicalValue(argument, *f, deleter, calleeAnalysis);
545+
canonicalizer.canonicalizeValueLifetime(argument);
546546
}
547547
}
548548
deleter.cleanupDeadInstructions();

test/SILOptimizer/shrink_borrow_scope.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ exit:
558558
// CHECK: [[LIFETIME_D:%[^,]+]] = begin_borrow [[INSTANCE_D]]
559559
// CHECK: struct $CDCase ([[LIFETIME_C]] : $C, [[LIFETIME_D]] : $D)
560560
// CHECK: end_borrow [[LIFETIME_D]]
561-
// CHECK: destroy_value [[INSTANCE_D]]
562561
// CHECK: end_borrow [[LIFETIME_C]]
562+
// CHECK: destroy_value [[INSTANCE_D]]
563563
// CHECK: return [[COPY_C]]
564564
// CHECK-LABEL: } // end sil function 'hoist_over_struct'
565565
sil [ossa] @hoist_over_struct : $@convention(thin) (@owned C, @owned D) -> @owned C {

test/SILOptimizer/shrink_borrow_scope.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public func eliminate_copy_of_returned_then_consumed_owned_value(arg: __owned An
2727
// no copy of 'x'
2828
_ = consumeAndProduce(x)
2929
// CHECK: [[RESULT:%[^,]+]] = apply {{%[^,]+}}([[MOVE_X]])
30-
// release result
3130
// release arg
32-
// CHECK: destroy_value [[ARG]]
31+
// release result
3332
// CHECK: destroy_value [[RESULT]]
33+
// CHECK: destroy_value [[ARG]]
3434
// CHECK-LABEL: } // end sil function 'eliminate_copy_of_returned_then_consumed_owned_value'
3535
}
3636

0 commit comments

Comments
 (0)