[PATCH] D134003: [MachineCSE] Add a threshold to avoid spending too much time in isProfitableToCSE
Pengxuan Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 16 13:35:35 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59365f33e27b: [MachineCSE] Add a threshold to avoid spending too much time in… (authored by pzheng).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134003/new/
https://reviews.llvm.org/D134003
Files:
llvm/lib/CodeGen/MachineCSE.cpp
Index: llvm/lib/CodeGen/MachineCSE.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCSE.cpp
+++ llvm/lib/CodeGen/MachineCSE.cpp
@@ -60,6 +60,11 @@
"Number of cross-MBB physreg referencing CS eliminated");
STATISTIC(NumCommutes, "Number of copies coalesced after commuting");
+// Threshold to avoid excessive cost to compute isProfitableToCSE.
+static cl::opt<int>
+ CSUsesThreshold("csuses-threshold", cl::Hidden, cl::init(1024),
+ cl::desc("Threshold for the size of CSUses"));
+
namespace {
class MachineCSE : public MachineFunctionPass {
@@ -443,15 +448,23 @@
if (Register::isVirtualRegister(CSReg) && Register::isVirtualRegister(Reg)) {
MayIncreasePressure = false;
SmallPtrSet<MachineInstr*, 8> CSUses;
+ int NumOfUses = 0;
for (MachineInstr &MI : MRI->use_nodbg_instructions(CSReg)) {
CSUses.insert(&MI);
- }
- for (MachineInstr &MI : MRI->use_nodbg_instructions(Reg)) {
- if (!CSUses.count(&MI)) {
+ // Too costly to compute if NumOfUses is very large. Conservatively assume
+ // MayIncreasePressure to avoid spending too much time here.
+ if (++NumOfUses > CSUsesThreshold) {
MayIncreasePressure = true;
break;
}
}
+ if (!MayIncreasePressure)
+ for (MachineInstr &MI : MRI->use_nodbg_instructions(Reg)) {
+ if (!CSUses.count(&MI)) {
+ MayIncreasePressure = true;
+ break;
+ }
+ }
}
if (!MayIncreasePressure) return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134003.460884.patch
Type: text/x-patch
Size: 1560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220916/7acf5490/attachment.bin>
More information about the llvm-commits
mailing list