This is an archive of the discontinued LLVM Phabricator instance.

[MachineSink] Clear kill flags on operands outside loop
ClosedPublic

Authored by critson on May 31 2022, 11:10 PM.

Details

Summary

If an instruction is sunk into a loop then any kill flags on
operands declared outside the loop must be cleared as these
will be live for all loop iterations.

Fixes #46827

Diff Detail

Event Timeline

critson created this revision.May 31 2022, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 11:10 PM
critson requested review of this revision.May 31 2022, 11:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 11:10 PM
fhahn added a comment.Jun 6 2022, 6:38 AM

Could the test case by just a MIR test case that only runs MachineSink?

MatzeB added inline comments.Jun 6 2022, 9:46 AM
llvm/lib/CodeGen/MachineSink.cpp
1496–1504

What about this code that already exists, is it not working for this example? If so, can it be fixed?

critson updated this revision to Diff 437472.Jun 16 2022, 1:39 AM
critson marked an inline comment as done.
  • Address reviewer comments
  • Change to MIR test

Could the test case by just a MIR test case that only runs MachineSink?

Yes, I'll do this.

llvm/lib/CodeGen/MachineSink.cpp
1496–1504

RegsToClearKillFlags is only populated by SinkInstruction, the code path for SinkIntoCycle is different.
However I agree this should generally use the same methodology for clearing the flags, so I have changed the code to populate RegsToClearKillFlags as part of SinkIntoCycle instead of what I initially wrote.

MatzeB accepted this revision.Jun 16 2022, 2:09 PM

LGTM

This revision is now accepted and ready to land.Jun 16 2022, 2:09 PM
MatzeB added inline comments.Jun 16 2022, 2:11 PM
llvm/lib/CodeGen/MachineSink.cpp
1294

Change this to MO.readsReg() As we don't need to deal with things like undef uses or internal bundle reads.

critson updated this revision to Diff 438259.Jun 19 2022, 11:13 PM
  • readsReg() instead of isUse()
critson marked an inline comment as done.Jun 19 2022, 11:46 PM
critson updated this revision to Diff 439617.Jun 23 2022, 10:02 PM
  • Rebase before commit
This revision was landed with ongoing or failed builds.Jun 23 2022, 10:03 PM
This revision was automatically updated to reflect the committed changes.