[llvm] 6bf2791 - [MachineSSAUpdater] compile time improvement in GetValueInMiddleOfBlock

Serguei Katkov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 04:30:15 PDT 2022


Author: Serguei Katkov
Date: 2022-06-14T18:00:34+07:00
New Revision: 6bf27918144cb843cf5ae9a93cb5f936730f3cce

URL: https://github.com/llvm/llvm-project/commit/6bf27918144cb843cf5ae9a93cb5f936730f3cce
DIFF: https://github.com/llvm/llvm-project/commit/6bf27918144cb843cf5ae9a93cb5f936730f3cce.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/CodeGen/MachineSSAUpdater.cpp
    llvm/lib/Transforms/Utils/SSAUpdater.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineSSAUpdater.cpp b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
index 48076663ddf5..f58b0f77897d 100644
--- a/llvm/lib/CodeGen/MachineSSAUpdater.cpp
+++ b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
@@ -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.

diff  --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp
index 37019e3bf95b..69c93b304260 100644
--- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp
+++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp
@@ -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;


        


More information about the llvm-commits mailing list