[CopyPropagation] Delete dead copy_values.

When canonicalizing an owned value's lifetime, also check whether the
value is dead.  If it is, track it for deletion.  In particular, this
eliminates dead copy_values.
This commit is contained in:
Nate Chandler
2022-03-23 17:00:35 -07:00
parent c6de8088c6
commit 9492619319
2 changed files with 28 additions and 0 deletions

View File

@@ -559,6 +559,9 @@ void CopyPropagation::run() {
while (!defWorklist.ownedValues.empty()) {
SILValue def = defWorklist.ownedValues.pop_back_val();
canonicalizer.canonicalizeValueLifetime(def);
// Copies of borrowed values may be dead.
if (auto *inst = def->getDefiningInstruction())
deleter.trackIfDead(inst);
}
// Recursively cleanup dead defs after removing uses.
deleter.cleanupDeadInstructions();