[llvm] r331502 - [MachineCSE] Rewrite a loop checking if a block is in a set of blocks without using a set. NFC.
Michael Zolotukhin via llvm-commits
llvm-commits at lists.llvm.org
Thu May 3 18:40:05 PDT 2018
Author: mzolotukhin
Date: Thu May 3 18:40:05 2018
New Revision: 331502
URL: http://llvm.org/viewvc/llvm-project?rev=331502&view=rev
Log:
[MachineCSE] Rewrite a loop checking if a block is in a set of blocks without using a set. NFC.
Summary:
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.
Reviewers: davide
Subscribers: hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D46411
Modified:
llvm/trunk/lib/CodeGen/MachineCSE.cpp
Modified: llvm/trunk/lib/CodeGen/MachineCSE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineCSE.cpp?rev=331502&r1=331501&r2=331502&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineCSE.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineCSE.cpp Thu May 3 18:40:05 2018
@@ -445,15 +445,13 @@ bool MachineCSE::isProfitableToCSE(unsig
// 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) {
More information about the llvm-commits
mailing list