Skip to content

Commit 996fd8b

Browse files
committed
Bail out from deleting a dead objection on seeing stores with lexical non-trivial source
1 parent d44ce9d commit 996fd8b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,17 @@ static bool canZapInstruction(SILInstruction *Inst, bool acceptRefCountInsts,
289289
if (isa<DestroyAddrInst>(Inst))
290290
return true;
291291

292-
// If we see a store here, we have already checked that we are storing into
293-
// the pointer before we added it to the worklist, so we can skip it.
292+
// We have already checked that we are storing into the pointer before we
293+
// added it to the worklist. Here, in the case we are allowing non-trivial
294+
// stores, check if the store's source is lexical, if so return false.
295+
// Deleting a dead object with non-trivial stores, will need compensating
296+
// destroys at the store for it's source, which will shorten the lifetime of
297+
// the store's source.
294298
if (auto *store = dyn_cast<StoreInst>(Inst)) {
295-
return !onlyAcceptTrivialStores ||
296-
store->getSrc()->getType().isTrivial(*store->getFunction());
299+
auto storeSrc = store->getSrc();
300+
return storeSrc->getType().isTrivial(*store->getFunction()) ||
301+
(!onlyAcceptTrivialStores &&
302+
(!store->getFunction()->hasOwnership() || !storeSrc->isLexical()));
297303
}
298304

299305
// Conceptually this instruction has no side-effects.
@@ -943,11 +949,18 @@ bool DeadObjectElimination::processKeyPath(KeyPathInst *KPI) {
943949
return false;
944950
}
945951

946-
// In non-ossa, bail out if we have non-trivial pattern operands
947-
if (!KPI->getFunction()->hasOwnership()) {
948-
for (const Operand &Op : KPI->getPatternOperands()) {
949-
if (!Op.get()->getType().isTrivial(*KPI->getFunction()))
952+
bool hasOwnership = KPI->getFunction()->hasOwnership();
953+
for (const Operand &Op : KPI->getPatternOperands()) {
954+
// In non-ossa, bail out if we have non-trivial pattern operands.
955+
if (!hasOwnership) {
956+
if (Op.get()->getType().isTrivial(*KPI->getFunction()))
950957
return false;
958+
continue;
959+
}
960+
// In ossa, bail out if we have non-trivial pattern operand values that are
961+
// lexical.
962+
if (Op.get()->isLexical()) {
963+
return false;
951964
}
952965
}
953966

0 commit comments

Comments
 (0)