[PATCH] D46411: [MachineCSE] Rewrite a loop checking if a block is in a set of blocks without using a set. NFC.

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 3 16:47:31 PDT 2018


mzolotukhin created this revision.
mzolotukhin added a reviewer: davide.
Herald added a subscriber: hiraditya.

Using a set is unnecessary here an in some cases (see e.g. PR37277)
takes significant amount of time to just insert values into it. In this
particular case all we need is just to check if we find the block we are
looking for or not.


Repository:
  rL LLVM

https://reviews.llvm.org/D46411

Files:
  llvm/lib/CodeGen/MachineCSE.cpp


Index: llvm/lib/CodeGen/MachineCSE.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCSE.cpp
+++ llvm/lib/CodeGen/MachineCSE.cpp
@@ -445,15 +445,13 @@
   // Heuristics #3: If the common subexpression is used by PHIs, do not reuse
   // it unless the defined value is already used in the BB of the new use.
   bool HasPHI = false;
-  SmallPtrSet<MachineBasicBlock*, 4> CSBBs;
-  for (MachineInstr &MI : MRI->use_nodbg_instructions(CSReg)) {
-    HasPHI |= MI.isPHI();
-    CSBBs.insert(MI.getParent());
+  for (MachineInstr &UseMI : MRI->use_nodbg_instructions(CSReg)) {
+    HasPHI |= UseMI.isPHI();
+    if (UseMI.getParent() == MI->getParent())
+      return true;
   }
 
-  if (!HasPHI)
-    return true;
-  return CSBBs.count(MI->getParent());
+  return !HasPHI;
 }
 
 void MachineCSE::EnterScope(MachineBasicBlock *MBB) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46411.145116.patch
Type: text/x-patch
Size: 877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180503/0770cc0f/attachment.bin>


More information about the llvm-commits mailing list