This is an archive of the discontinued LLVM Phabricator instance.

[RegAlloc] Immediately delete dead instructions with live uses
ClosedPublic

Authored by rampitec on Aug 30 2021, 3:05 PM.

Details

Summary

When RA eliminated a dead def it can either immediately delete
the instruction itself or replace it with KILL to defer the
actual removal. If this instruction has a virtual register use
killing the register it will shrink the LI of the use. However,
if the LI covers the instruction and extends beyond it the
shrink will not happen. In fact that is impossible to shrink
such use because of the KILL still using it.

If later the LI of the use will be split at the KILL and the
KILL itself is eliminated after that point the new live segment
ends up at an invalid slot index.

This extremely rare condition was hit after D106408 which has
enabled rematerialization of such instructions. The replacement
with KILL is only done for rematerialized defs which became dead
and such rematerialization did not generally happen before.

The patch deletes an instruction immediately if it is a result
of rematerialization and has such use. An alternative would be
to prohibit a split at a KILL instruction, but it looks like it
is better to split a live range rather then keeping a killed
instruction just in case it can be rematerialized further.

Fixes PR51655.

Diff Detail

Event Timeline

rampitec created this revision.Aug 30 2021, 3:05 PM
rampitec requested review of this revision.Aug 30 2021, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2021, 3:05 PM
qcolombet accepted this revision.Aug 31 2021, 1:42 PM
qcolombet added inline comments.
llvm/lib/CodeGen/LiveRangeEdit.cpp
369–373

Typo: immedialtely => immediately

llvm/test/CodeGen/X86/pr51655.mir
4 ↗(On Diff #369562)

Could you set a more descriptive file name like delete-dead-instrs-with-live-uses.mir?

This revision is now accepted and ready to land.Aug 31 2021, 1:42 PM
rampitec updated this revision to Diff 369788.Aug 31 2021, 1:47 PM
rampitec marked 2 inline comments as done.

Fixed comment typo and renamed the test.

This revision was landed with ongoing or failed builds.Aug 31 2021, 2:00 PM
This revision was automatically updated to reflect the committed changes.