Skip to content

Commit 698ed8e

Browse files
committed
Make Ownership RAUW checks more precise - allows more optimization.
Call findOwnershipReferenceRoot when checking for guaranteed values from SILFunctionArgument. TODO: We need to add a component path to a reference root abstraction to handle references that come from a struct_extract or tuple_extract.
1 parent c6d9084 commit 698ed8e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ static bool canFixUpOwnershipForRAUW(SILValue oldValue, SILValue newValue,
350350
if (oldValue.getOwnershipKind() != OwnershipKind::Guaranteed)
351351
return true;
352352

353+
SILValue newRoot = findOwnershipReferenceRoot(newValue);
354+
if (newRoot && isa<SILFunctionArgument>(newRoot))
355+
return true;
356+
353357
// Check that the old lifetime can be extended and record the necessary
354358
// book-keeping in the OwnershipFixupContext.
355359
context.clear();
@@ -870,9 +874,10 @@ SILValue
870874
OwnershipLifetimeExtender::borrowOverValue(SILValue newValue,
871875
SILValue guaranteedValue) {
872876
// Avoid borrowing guaranteed function arguments.
873-
if (isa<SILFunctionArgument>(newValue)
874-
&& newValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
875-
return newValue;
877+
if (newValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
878+
SILValue newRoot = findOwnershipReferenceRoot(newValue);
879+
if (newRoot && isa<SILFunctionArgument>(newRoot))
880+
return newValue;
876881
}
877882
auto borrowedValue = BorrowedValue(guaranteedValue);
878883
if (borrowedValue && borrowedValue.isLocalScope()) {

0 commit comments

Comments
 (0)