[DCE] Process instructions added during deletion.

In cea0f00598, `InstructionDeleter` began
deleting `load [take]` instructions.  Analogous to how it creates a
`destroy_value` when deleting an instruction which consumes a value, in
the case of deleting a `load [take]` the `InstructionDeleter` inserts a
compensating `destroy_addr`.

Previously, `DeadCodeElimination` did not observe the creation of any
instructions created by the `InstructionDeleter`.  In the case of the
newly created `destroy_addr`, DCE didn't mark that the `destroy_addr`
was live and so deleted it.  The result was a leak.

Here, this is fixed by passing an `InstModCallbacks`--with an
`onCreateNewInst` implementation--down into `erasePhiArgument` that
eventually invokes the `InstructionDeleter`.  When the
`InstructionDeleter` creates a new instruction, DCE marks it live.
This commit is contained in:
Nate Chandler
2023-11-15 14:28:42 -08:00
parent 7fd5cae61a
commit ae6868a296
4 changed files with 58 additions and 14 deletions

View File

@@ -658,7 +658,9 @@ bool DCE::removeDead() {
endLifetimeOfLiveValue(phiArg->getIncomingPhiValue(pred), insertPt);
}
erasePhiArgument(&BB, i);
erasePhiArgument(&BB, i, /*cleanupDeadPhiOps=*/true,
InstModCallbacks().onCreateNewInst(
[&](auto *inst) { markInstructionLive(inst); }));
Changed = true;
BranchesChanged = true;
}