This is an archive of the discontinued LLVM Phabricator instance.

[MachineSSAUpdater] compile time improvement in GetValueInMiddleOfBlock
ClosedPublic

Authored by skatkov on May 27 2022, 12:09 AM.

Details

Summary

GetValueInMiddleOfBlock uses result of GetValueAtEndOfBlockInternal if there is no value
defined for current basic block.

If there is already a value it tries (in this order):

  • to find single register coming from all predecessors
  • find existing phi node which matches our incoming registers
  • build new phi.

The compile time improvement is to use current available value if
it is defined out of current BB or it is a PHI register.
This is due to it can be used in the middle basic block.

Diff Detail

Event Timeline

skatkov created this revision.May 27 2022, 12:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 27 2022, 12:09 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
skatkov requested review of this revision.May 27 2022, 12:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 27 2022, 12:09 AM
skatkov updated this revision to Diff 433957.Jun 2 2022, 10:58 PM
skatkov retitled this revision from [MachineSSAUpdater] Re-use existing phi node in GetValueInMiddleOfBlock to [MachineSSAUpdater] compile time improvement in GetValueInMiddleOfBlock.
skatkov edited the summary of this revision. (Show Details)

Looks straightforward enough to me. If the value is a PHI, it must be at the beginning of the current block. If it is outside this block, then whoever registered it is confident that it dominates this block. Is it correct that the SSAUpdater will not end up in a state where it tries to use a phi to produce another phi in the same block? Because that might race against the assumption that the used phi is available earlier in the block.

Same typo in the change description, last paragraph ... middle "of" the block.

llvm/lib/CodeGen/MachineSSAUpdater.cpp
156–157

middle "of" the block?

llvm/lib/Transforms/Utils/SSAUpdater.cpp
104

middle "of" the block?

skatkov added a comment.EditedJun 14 2022, 1:37 AM

Looks straightforward enough to me. If the value is a PHI, it must be at the beginning of the current block. If it is outside this block, then whoever registered it is confident that it dominates this block. Is it correct that the SSAUpdater will not end up in a state where it tries to use a phi to produce another phi in the same block? Because that might race against the assumption that the used phi is available earlier in the block.

That is my understanding. As I see GetValueInMiddleOfBlock is not used anywhere to build new phi, its result is not saved to any internal structures, so I do not change anything as I see.

skatkov updated this revision to Diff 436700.Jun 14 2022, 1:44 AM

Comments updated.

sameerds accepted this revision.Jun 14 2022, 3:56 AM
This revision is now accepted and ready to land.Jun 14 2022, 3:56 AM
This revision was landed with ongoing or failed builds.Jun 14 2022, 4:30 AM
This revision was automatically updated to reflect the committed changes.