Skip to content

Commit 522dc9d

Browse files
committed
InstructionDeleter - delete dead alloc_stack
1 parent 17e13d4 commit 522dc9d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,11 @@ bool swift::hasOnlyEndOfScopeOrEndOfLifetimeUses(SILInstruction *inst) {
216216
for (Operand *use : result->getUses()) {
217217
SILInstruction *user = use->getUser();
218218
bool isDebugUser = user->isDebugInstruction();
219-
if (!isa<DestroyValueInst>(user) && !isa<EndLifetimeInst>(user) &&
220-
!isEndOfScopeMarker(user) && !isDebugUser)
219+
if (!isa<DestroyValueInst>(user) && !isa<EndLifetimeInst>(user)
220+
&& !isa<DeallocStackInst>(user) && !isEndOfScopeMarker(user)
221+
&& !isDebugUser) {
221222
return false;
223+
}
222224
// Include debug uses only in Onone mode.
223225
if (isDebugUser && inst->getFunction()->getEffectiveOptimizationMode() <=
224226
OptimizationMode::NoOptimization)

lib/SILOptimizer/Utils/InstructionDeleter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
6666
return true;
6767

6868
switch (inst->getKind()) {
69+
case SILInstructionKind::AllocStackInst: {
70+
// An alloc_stack only used by dealloc_stack is dead.
71+
return
72+
fun->getEffectiveOptimizationMode() > OptimizationMode::NoOptimization
73+
|| !cast<AllocStackInst>(inst)->getVarInfo();
74+
}
6975
case SILInstructionKind::LoadBorrowInst: {
7076
// A load_borrow only used in an end_borrow is dead.
7177
return true;
@@ -205,8 +211,8 @@ void InstructionDeleter::deleteWithUses(SILInstruction *inst, bool fixLifetimes,
205211
auto uses = llvm::to_vector<4>(result->getUses());
206212
for (Operand *use : uses) {
207213
SILInstruction *user = use->getUser();
208-
assert(forceDeleteUsers || isIncidentalUse(user) ||
209-
isa<DestroyValueInst>(user));
214+
assert(forceDeleteUsers || isIncidentalUse(user)
215+
|| isa<DestroyValueInst>(user) || isa<DeallocStackInst>(user));
210216
assert(!isa<BranchInst>(user) && "can't delete phis");
211217

212218
toDeleteInsts.push_back(user);

0 commit comments

Comments
 (0)