[DCE] Add delete handler for phi erasure.

Set CallsChanged when appropriate and increment NumDeletedInsts.
This commit is contained in:
Nate Chandler
2024-12-19 14:21:48 -08:00
parent 00116edcfb
commit f75f12b681

View File

@@ -731,9 +731,17 @@ bool DCE::removeDead() {
endLifetimeOfLiveValue(predOp, insertPt);
}
}
erasePhiArgument(&BB, i, /*cleanupDeadPhiOps=*/true,
InstModCallbacks().onCreateNewInst(
[&](auto *inst) { markInstructionLive(inst); }));
erasePhiArgument(
&BB, i, /*cleanupDeadPhiOps=*/true,
InstModCallbacks()
.onCreateNewInst([&](auto *inst) { markInstructionLive(inst); })
.onDelete([&](auto *inst) {
inst->replaceAllUsesOfAllResultsWithUndef();
if (isa<ApplyInst>(inst))
CallsChanged = true;
++NumDeletedInsts;
inst->eraseFromParent();
}));
Changed = true;
BranchesChanged = true;
}