[MachineSSAUpdater] compile time improvement in GetValueInMiddleOfBlock

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.

Reviewed By: sameerds
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D126523
This commit is contained in:
Serguei Katkov 2022-05-26 11:51:36 +07:00
parent b4cf74dc9e
commit 6bf2791814
2 changed files with 16 additions and 0 deletions

View File

@ -152,6 +152,14 @@ Register MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB,
if (!HasValueForBlock(BB))
return GetValueAtEndOfBlockInternal(BB, ExistingValueOnly);
// Ok, we have already got a value for this block. If it is out of our block
// or it is a phi - we can re-use it as it will be defined in the middle of
// block as well.
Register defR = getAvailableVals(AV).lookup(BB);
if (auto I = MRI->getVRegDef(defR))
if (I->isPHI() || I->getParent() != BB)
return defR;
// If there are no predecessors, just return undef.
if (BB->pred_empty()) {
// If we cannot insert new instructions, just return $noreg.

View File

@ -100,6 +100,14 @@ Value *SSAUpdater::GetValueInMiddleOfBlock(BasicBlock *BB) {
if (!HasValueForBlock(BB))
return GetValueAtEndOfBlock(BB);
// Ok, we have already got a value for this block. If it is out of our block
// or it is a phi - we can re-use it as it will be defined in the middle of
// block as well.
Value *defV = FindValueForBlock(BB);
if (auto I = dyn_cast<Instruction>(defV))
if (isa<PHINode>(I) || I->getParent() != BB)
return defV;
// Otherwise, we have the hard case. Get the live-in values for each
// predecessor.
SmallVector<std::pair<BasicBlock *, Value *>, 8> PredValues;