Skip to content

Commit 6e850d7

Browse files
committed
[move-only] When storing a trivial field of a borrowed parameter, treat the store as a trivial use.
rdar://111354827
1 parent 60d82c7 commit 6e850d7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureUtils.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ bool Implementation::gatherUses(SILValue value) {
342342
return false;
343343
}
344344

345+
// Check if our use type is trivial. In such a case, just treat this as a
346+
// liveness use.
347+
SILType type = nextUse->get()->getType();
348+
if (type.isTrivial(nextUse->getUser()->getFunction())) {
349+
LLVM_DEBUG(llvm::dbgs() << " Found non lifetime ending use!\n");
350+
blocksToUses.insert(nextUse->getParentBlock(),
351+
{nextUse,
352+
{liveness.getNumSubElements(), *leafRange,
353+
false /*is lifetime ending*/}});
354+
liveness.updateForUse(nextUse->getUser(), *leafRange,
355+
false /*is lifetime ending*/);
356+
instToInterestingOperandIndexMap.insert(nextUse->getUser(), nextUse);
357+
continue;
358+
}
359+
345360
LLVM_DEBUG(llvm::dbgs() << " Found lifetime ending use!\n");
346361
destructureNeedingUses.push_back(nextUse);
347362
blocksToUses.insert(nextUse->getParentBlock(),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-sil -O -sil-verify-all -verify -enable-experimental-feature NoImplicitCopy -enable-experimental-feature MoveOnlyClasses %s
2+
3+
struct Test: ~Copyable {
4+
public let baseAddress: UnsafeRawPointer
5+
public let count: Int
6+
}
7+
8+
extension Test {
9+
10+
public static func ==(lhs: borrowing Test, rhs: borrowing Test) -> Bool {
11+
let count = lhs.count
12+
guard count == rhs.count else { return false }
13+
14+
if count == 0 { return true } else if lhs.baseAddress == rhs.baseAddress { return true }
15+
if count == 1 || lhs.baseAddress == rhs.baseAddress { return true }
16+
17+
return lhs.baseAddress.load(as: UInt8.self) == rhs.baseAddress.load(as: UInt8.self)
18+
}
19+
}

0 commit comments

Comments
 (0)