This is an archive of the discontinued LLVM Phabricator instance.

[PHIElimination] Update LiveVariables after handling an unspillable terminator
ClosedPublic

Authored by foad on Oct 1 2021, 7:51 AM.

Details

Summary

Update the LiveVariables analysis after the special handling for
unspillable terminators which was added in D91358. This is just enough
to fix some "Block should not be in AliveBlocks" / "Block missing from
AliveBlocks" errors in the codegen test suite when machine verification
is forced to run after PHIElimination (currently it is disabled).

Diff Detail

Event Timeline

foad created this revision.Oct 1 2021, 7:51 AM
foad requested review of this revision.Oct 1 2021, 7:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 1 2021, 7:51 AM

This sounds conceptually OK to me - that we would need to update the live variables for unspillable terminators - but I don't know a lot about updating LV, so don't know a lot of the details.

Should the Incoming blocks be the Src blocks, or should it be a combination of Incoming and Src?

foad added a comment.Oct 4 2021, 3:38 AM

This sounds conceptually OK to me - that we would need to update the live variables for unspillable terminators - but I don't know a lot about updating LV, so don't know a lot of the details.

Should the Incoming blocks be the Src blocks, or should it be a combination of Incoming and Src?

I think at this point IncomingReg is a freshly created register, so it won't have any AliveBlocks yet.

Having said that I admit I don't understand all the details either, I was just doing the minimum to get verification to pass, since my next project is to remove LiveVariables anyway in favour of LiveIntervals.

MatzeB accepted this revision.Oct 4 2021, 12:32 PM

LGTM.

Please try if the suggested changes work. If not then I'm fine with the change as-is.

llvm/lib/CodeGen/PHIElimination.cpp
465–471

As far as I can tell, the other code here that creates COPYs etc. does not bother creating a information for IncomingReg. So maybe we should do the same here and just concern ourself with dropping the old info?

This revision is now accepted and ready to land.Oct 4 2021, 12:32 PM

If it helps, I would expect the unspillable terminators to look like:

bb1:
  ..
  %r = UnspillableTerminator ..
bb2:
  %p = phi %r, ...
  ... uses of %p

In our usecase in the Arm backend, bb2 will be a loop header, usually with a single block (but not necessarily, especially in the future).

foad added a comment.Oct 5 2021, 6:09 AM

If it helps, I would expect the unspillable terminators to look like:

bb1:
  ..
  %r = UnspillableTerminator ..
bb2:
  %p = phi %r, ...
  ... uses of %p

In our usecase in the Arm backend, bb2 will be a loop header, usually with a single block (but not necessarily, especially in the future).

In the tests I am looking at, there is a preheader block in between your bb1 and bb2, and %r is live-through the preheader.

foad added inline comments.Oct 5 2021, 6:12 AM
llvm/lib/CodeGen/PHIElimination.cpp
465–471

As far as I can tell, the other code here that creates COPYs etc. does not bother creating a information for IncomingReg.

There is certainly some existing code that updates LV info for IncomingReg, though I haven't looked at it in detail.

So maybe we should do the same here and just concern ourself with dropping the old info?

That only fixes the "Block should not be in AliveBlocks" errors, not the "Block missing from AliveBlocks" errors.