Page MenuHomePhabricator

[MachineDCE] Delete missed dead instructions after deleting PHI
Needs ReviewPublic

Authored by nemanjai on Aug 28 2020, 1:02 PM.

Details

Reviewers
sunfish
MatzeB
efriedma
Group Reviewers
Restricted Project
Summary

Machine DCE does a linear bottom-up pass to detect dead instructions and delete them. The idea with the bottom-up traversal is to delete instructions before their inputs so that removal of a single user makes the def instruction dead.

This however does not work if the only user of an instruction is a PHI in a loop header. With this patch, DCE tracks instructions that have become dead when removing a PHI. At the end, if any of those still exist in their parent MBB, they're also deleted.

Diff Detail

Event Timeline

nemanjai created this revision.Aug 28 2020, 1:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2020, 1:02 PM
nemanjai requested review of this revision.Aug 28 2020, 1:02 PM
lkail edited reviewers, added: efriedma; removed: eli.friedman.Aug 28 2020, 4:45 PM

In general, this pass isn't going to see uses before defs; it's not CFG-sensitive at all. This isn't specific to PHI nodes. For virtual registers, maybe we could be doing something like the IR RecursivelyDeleteTriviallyDeadInstructions, to make sure we catch everything? (Well, everything a simple DCE can catch; ADCE is probably overkill.)

That doesn't really extend to physreg defs, though; we don't currently record the information necessary. Not sure if we can do anything about that cheaply.

llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
156

You can't use isDead() like this: it queries LivePhysRegs, which is only valid for the current MI.