diff --git a/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp b/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp index df56de8b58d..b2da63b6c58 100644 --- a/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp +++ b/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp @@ -283,8 +283,8 @@ void DCE::markLive() { } case SILInstructionKind::EndBorrowInst: { auto phi = PhiValue(I.getOperand(0)); - // If there is a pointer escape, disable DCE. - if (phi && hasPointerEscape(phi)) { + // If there is a pointer escape or phi is lexical, disable DCE. + if (phi && (hasPointerEscape(phi) || phi->isLexical())) { markInstructionLive(&I); } // The instruction is live only if it's operand value is also live @@ -320,10 +320,6 @@ void DCE::markLive() { disableBorrowDCE(root); } } - // If we have a lexical borrow scope, disable DCE. - if (borrowInst->isLexical()) { - disableBorrowDCE(borrowInst); - } break; } case SILInstructionKind::LoadBorrowInst: {