Skip to content

Commit f5c5c9e

Browse files
committed
In non-ossa, ban non-trivial stores to alloc_ref's projections even the dtor is not inlined
There is no implementation to handle insertion of compensating releases of the non-trivial store's src for this case. This never really happens, because destructor analysis is very limited and we end up banning alloc_ref with ref count instructions.
1 parent 768d98e commit f5c5c9e

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ hasUnremovableUsers(SILInstruction *allocation, UserList *Users,
384384
LLVM_DEBUG(llvm::dbgs() << " Analyzing Use Graph.");
385385

386386
SmallVector<RefElementAddrInst *, 8> refElementAddrs;
387-
bool deallocationMaybeInlined = false;
388387
BuiltinInst *destroyArray = nullptr;
389388
auto *allocRef = dyn_cast<AllocRefInstBase>(allocation);
390389

@@ -400,10 +399,8 @@ hasUnremovableUsers(SILInstruction *allocation, UserList *Users,
400399
continue;
401400
}
402401
if (auto *rea = dyn_cast<RefElementAddrInst>(I)) {
403-
if (!rea->getType().isTrivial(*rea->getFunction()))
402+
if (rea != allocation && !rea->getType().isTrivial(*rea->getFunction()))
404403
refElementAddrs.push_back(rea);
405-
} else if (isa<SetDeallocatingInst>(I)) {
406-
deallocationMaybeInlined = true;
407404
} else if (allocRef && Users && isDestroyArray(I)) {
408405
if (destroyArray)
409406
return true;
@@ -443,18 +440,14 @@ hasUnremovableUsers(SILInstruction *allocation, UserList *Users,
443440
if (destroyArray)
444441
return !onlyStoresToTailObjects(destroyArray, *Users, allocRef);
445442

446-
if (deallocationMaybeInlined) {
447-
// The alloc_ref is not destructed by a strong_release which is calling the
448-
// deallocator (destroying all stored properties).
449-
// In non-OSSA we cannot reliably track the lifetime of non-trivial stored
450-
// properties. Removing the dead alloc_ref might leak a property value.
451-
// TODO: in OSSA we can replace stores to properties with a destroy_value.
452-
for (RefElementAddrInst *rea : refElementAddrs) {
453-
// Re-run the check with not accepting non-trivial stores.
454-
if (hasUnremovableUsers(rea, nullptr, acceptRefCountInsts,
455-
/*onlyAcceptTrivialStores*/ true))
456-
return true;
457-
}
443+
// In non-OSSA we cannot reliably track the lifetime of non-trivial stored
444+
// properties. Removing the dead alloc_ref might leak a property value.
445+
// TODO: in OSSA we can replace stores to properties with a destroy_value.
446+
for (RefElementAddrInst *rea : refElementAddrs) {
447+
// Re-run the check with not accepting non-trivial stores.
448+
if (hasUnremovableUsers(rea, nullptr, acceptRefCountInsts,
449+
/*onlyAcceptTrivialStores*/ true))
450+
return true;
458451
}
459452

460453
return false;

0 commit comments

Comments
 (0)