[PATCH] D126523: [MachineSSAUpdater] compile time improvement in GetValueInMiddleOfBlock

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 22:58:55 PDT 2022


skatkov updated this revision to Diff 433957.
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.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126523/new/

https://reviews.llvm.org/D126523

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


Index: llvm/lib/Transforms/Utils/SSAUpdater.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SSAUpdater.cpp
+++ llvm/lib/Transforms/Utils/SSAUpdater.cpp
@@ -100,6 +100,14 @@
   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 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;
Index: llvm/lib/CodeGen/MachineSSAUpdater.cpp
===================================================================
--- llvm/lib/CodeGen/MachineSSAUpdater.cpp
+++ llvm/lib/CodeGen/MachineSSAUpdater.cpp
@@ -152,6 +152,14 @@
   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 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126523.433957.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220603/14f1b633/attachment.bin>


More information about the llvm-commits mailing list