@@ -153,6 +153,10 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
153153 // dead end blocks that use the value in a non-consuming way.
154154 //
155155 // TODO: There may be some way of sinking this into the loop below.
156+ //
157+ // FIXME: The haveAnyLocalScopes and destroy.empty() checks are relics of
158+ // attempts to handle dead end blocks during areUsesWithinLocalScope. If we
159+ // don't use dead end blocks at all, they should not be relevant.
156160 bool haveAnyLocalScopes =
157161 llvm::any_of (borrowScopeIntroducers, [](BorrowedValue borrowScope) {
158162 return borrowScope.isLocalScope ();
@@ -177,17 +181,16 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
177181 // anyways, we want to be conservative here and optimize only if we do not
178182 // need to insert an end_borrow since all of our borrow introducers are
179183 // non-local scopes.
184+ //
185+ // The call to areUsesWithinLocalScope cannot consider dead-end blocks. A
186+ // local borrow scope requires all its inner uses to be inside the borrow
187+ // scope, regardless of whether the end of the scope is inside a dead-end
188+ // block.
180189 {
181- bool foundNonDeadEnd = false ;
182- for (auto *d : destroys) {
183- foundNonDeadEnd |= !getDeadEndBlocks ().isDeadEnd (d->getParentBlock ());
184- }
185- if (!foundNonDeadEnd && haveAnyLocalScopes)
186- return false ;
187190 SmallVector<Operand *, 8 > scratchSpace;
188191 if (llvm::any_of (borrowScopeIntroducers, [&](BorrowedValue borrowScope) {
189- return !borrowScope.areUsesWithinLocalScope (lr.getAllConsumingUses (),
190- getDeadEndBlocks () );
192+ return !borrowScope.areUsesWithinLocalScope (lr.getAllConsumingUses (),
193+ nullptr );
191194 })) {
192195 return false ;
193196 }
@@ -216,7 +219,7 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
216219
217220 if (llvm::any_of (borrowScopeIntroducers, [&](BorrowedValue borrowScope) {
218221 return !borrowScope.areUsesWithinLocalScope (
219- phiArgLR.getAllConsumingUses (), getDeadEndBlocks () );
222+ phiArgLR.getAllConsumingUses (), nullptr );
220223 })) {
221224 return false ;
222225 }
0 commit comments