Skip to content

Commit df26a6d

Browse files
authored
Merge pull request #39805 from atrick/oou-opt-rauw
Improve OSSA rauw capability and add unit tests
2 parents f9643fd + 42cd5b8 commit df26a6d

File tree

2 files changed

+301
-85
lines changed

2 files changed

+301
-85
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

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

353+
SILValue newRoot = findOwnershipReferenceAggregate(newValue);
354+
if (newRoot && isa<SILFunctionArgument>(newRoot)
355+
&& newRoot->getOwnershipKind() == OwnershipKind::Guaranteed) {
356+
return true;
357+
}
353358
// Check that the old lifetime can be extended and record the necessary
354359
// book-keeping in the OwnershipFixupContext.
355360
context.clear();
@@ -870,9 +875,10 @@ SILValue
870875
OwnershipLifetimeExtender::borrowOverValue(SILValue newValue,
871876
SILValue guaranteedValue) {
872877
// Avoid borrowing guaranteed function arguments.
873-
if (isa<SILFunctionArgument>(newValue)
874-
&& newValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
875-
return newValue;
878+
if (newValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
879+
SILValue newRoot = findOwnershipReferenceAggregate(newValue);
880+
if (newRoot && isa<SILFunctionArgument>(newRoot))
881+
return newValue;
876882
}
877883
auto borrowedValue = BorrowedValue(guaranteedValue);
878884
if (borrowedValue && borrowedValue.isLocalScope()) {

0 commit comments

Comments
 (0)