Skip to content

Commit d1f8c04

Browse files
committed
Do not include transitive uses with none ownership during ownership rauw of guaranteed values
When we are populating transitive users while handling guaranteed values in ownership rauw, we were including values with none ownership. Example : rauw of %2 with a dominating value Here %arg1 was also considered a transitive use %2 = struct_extract %0 : $StructWithEnum2, #StructWithEnum2.val %copy = copy_value %2 : $FakeOptional2 switch_enum %2 : $FakeOptional2, case #FakeOptional2.some1!enumelt:bb5, case #FakeOptional2.some2!enumelt:bb6 bb5(%arg1 : $UInt): br bb7(%arg1 : $UInt) bb6(%arg2 : @guaranteed $Klass): %4 = unchecked_trivial_bit_cast %arg2 : $Klass to $UInt br bb7(%4 : $UInt) This is incorrect because %arg1 is a trivial value, and this also leads to ValueLifetimeAnalysis needing a split for finding a frontier for the use of %arg1 in the branch instruction. In ossa, we should never have to split edges for finding frontiers, because we do not have critical edges.
1 parent 8431ceb commit d1f8c04

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ insertOwnedBaseValueAlongBranchEdge(BranchInst *bi, SILValue innerCopy,
391391
return phiArg;
392392
}
393393

394-
static void getAllBorrowedValueUsePoints(
394+
static void getAllNonTrivialUsePointsOfBorrowedValue(
395395
SILValue value, SmallVectorImpl<Operand *> &usePoints,
396396
SmallVectorImpl<BorrowingOperand> &reborrowPoints) {
397397
assert(value.getOwnershipKind() == OwnershipKind::Guaranteed);
@@ -407,6 +407,9 @@ static void getAllBorrowedValueUsePoints(
407407
for (unsigned i = firstOffset; i < usePoints.size(); ++i) {
408408
if (auto fOperand = ForwardingOperand::get(usePoints[i])) {
409409
fOperand->visitForwardedValues([&](SILValue transitiveValue) {
410+
// Do not include transitive uses with 'none' ownership
411+
if (transitiveValue.getOwnershipKind() == OwnershipKind::None)
412+
return true;
410413
for (auto *transitiveUse : transitiveValue->getUses())
411414
usePoints.push_back(transitiveUse);
412415
return true;
@@ -685,8 +688,8 @@ SILBasicBlock::iterator OwnershipRAUWUtility::handleGuaranteed() {
685688
// workspace.
686689
SmallVector<Operand *, 32> usePoints;
687690
SmallVector<BorrowingOperand, 8> recursiveBorrowScopeReborrows;
688-
getAllBorrowedValueUsePoints(oldValue, usePoints,
689-
recursiveBorrowScopeReborrows);
691+
getAllNonTrivialUsePointsOfBorrowedValue(oldValue, usePoints,
692+
recursiveBorrowScopeReborrows);
690693

691694
// If we have any transitive reborrows on sub-borrows.
692695
if (recursiveBorrowScopeReborrows.size())

0 commit comments

Comments
 (0)