@@ -943,23 +943,9 @@ BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUses(
943943 makeUserRange (guaranteedUsePoints));
944944}
945945
946- // Return the borrow position when replacing guaranteedValue with newValue.
947- //
948- // Precondition: newValue's block dominates and reaches guaranteedValue's block.
949- //
950- // Postcondition: The returned instruction's block is guaranteedValue's block.
951- //
952- // If \p newValue and \p guaranteedValue are in the same block, borrow at the
953- // newValue just in case it is defined later in the block (to avoid scanning
954- // instructions). Otherwise, borrow in the guaranteedValue's block to avoid
955- // introducing the borrow scope too early--not only would this require extra
956- // cleanup, but it would hinder optimization.
957- static SILBasicBlock::iterator getBorrowPoint (SILValue newValue,
958- SILValue guaranteedValue) {
959- if (newValue->getParentBlock () == guaranteedValue->getParentBlock ())
960- return newValue->getNextInstruction ()->getIterator ();
961-
962- return guaranteedValue->getNextInstruction ()->getIterator ();
946+ // Return the borrow position when replacing oldValue.
947+ static SILBasicBlock::iterator getBorrowPoint (SILValue oldValue) {
948+ return oldValue->getDefiningInsertionPoint ()->getIterator ();
963949}
964950
965951// / Borrow \p newValue over the lifetime of \p guaranteedValue. Return the
@@ -991,7 +977,7 @@ OwnershipLifetimeExtender::borrowOverValue(SILValue newValue,
991977 return newValue;
992978
993979 // FIXME: use GuaranteedOwnershipExtension
994- auto borrowPt = getBorrowPoint (newValue, guaranteedValue);
980+ auto borrowPt = getBorrowPoint (guaranteedValue);
995981 return borrowCopyOverGuaranteedUses (
996982 newValue, borrowPt, ArrayRef<Operand *>(ctx.guaranteedUsePoints ));
997983}
@@ -1151,7 +1137,7 @@ SILValue OwnershipRAUWPrepare::prepareUnowned(SILValue newValue) {
11511137 }
11521138
11531139 auto extender = getLifetimeExtender ();
1154- auto borrowPt = getBorrowPoint (newValue, oldValue);
1140+ auto borrowPt = getBorrowPoint (oldValue);
11551141 SILValue borrow = extender.borrowCopyOverGuaranteedUses (
11561142 newValue, borrowPt, oldValue->getUses ());
11571143 return borrow;
@@ -1267,7 +1253,7 @@ OwnershipRAUWHelper::getReplacementAddress() {
12671253 // value. Then we RAUW as appropriate.
12681254 OwnershipLifetimeExtender extender{*ctx};
12691255 auto base = ctx->extraAddressFixupInfo .base ;
1270- auto borrowPt = getBorrowPoint (newValue, oldValue);
1256+ auto borrowPt = getBorrowPoint (oldValue);
12711257 // FIXME: why does this use allAddressUsesFromOldValue instead of
12721258 // guaranteedUsePoints?
12731259 BeginBorrowInst *bbi = extender.borrowCopyOverGuaranteedUses (
0 commit comments