[PATCH] D61397: [DAGCombiner] Limit number of nodes to explore, to avoid quadratic compile time.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 05:43:35 PDT 2019
fhahn updated this revision to Diff 197761.
fhahn added a comment.
Relax limits to 1000 nodes to explore. Further experimenting showed that those
bigger limits are still sufficient to ensure limiting quadratic compile time.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61397/new/
https://reviews.llvm.org/D61397
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -1764,6 +1764,12 @@
}
SDValue DAGCombiner::visitTokenFactor(SDNode *N) {
+ // Limit the number of nodes to explore, to avoid quadratic compile times.
+ // The limit helps to limit compile time for basic blocks with a large number
+ // of stores.
+ if (N->getNumOperands() > 1000)
+ return SDValue();
+
// If N has two operands, where one has an input chain equal to the other,
// the 'other' chain is redundant.
if (N->getNumOperands() == 2) {
@@ -14837,9 +14843,15 @@
RootNode = St->getChain().getNode();
+ // Limit the number of nodes to explore, to avoid quadratic compile times.
+ // The limit helps to limit compile time for basic blocks with a large number
+ // of stores.
+ unsigned MaxNumberOfNodesToCheck = 1000;
if (LoadSDNode *Ldn = dyn_cast<LoadSDNode>(RootNode)) {
RootNode = Ldn->getChain().getNode();
- for (auto I = RootNode->use_begin(), E = RootNode->use_end(); I != E; ++I)
+ for (auto I = RootNode->use_begin(), E = RootNode->use_end(); I != E; ++I) {
+ if (!MaxNumberOfNodesToCheck--)
+ break;
if (I.getOperandNo() == 0 && isa<LoadSDNode>(*I)) // walk down chain
for (auto I2 = (*I)->use_begin(), E2 = (*I)->use_end(); I2 != E2; ++I2)
if (I2.getOperandNo() == 0)
@@ -14849,15 +14861,21 @@
if (CandidateMatch(OtherST, Ptr, PtrDiff))
StoreNodes.push_back(MemOpLink(OtherST, PtrDiff));
}
- } else
- for (auto I = RootNode->use_begin(), E = RootNode->use_end(); I != E; ++I)
- if (I.getOperandNo() == 0)
+ }
+ } else {
+ for (auto I = RootNode->use_begin(), E = RootNode->use_end(); I != E; ++I) {
+ if (!MaxNumberOfNodesToCheck--)
+ break;
+ if (I.getOperandNo() == 0) {
if (StoreSDNode *OtherST = dyn_cast<StoreSDNode>(*I)) {
BaseIndexOffset Ptr;
int64_t PtrDiff;
if (CandidateMatch(OtherST, Ptr, PtrDiff))
StoreNodes.push_back(MemOpLink(OtherST, PtrDiff));
}
+ }
+ }
+ }
}
// We need to check that merging these stores does not cause a loop in
@@ -19978,7 +19996,13 @@
// Add ST's interval.
Intervals.insert(0, (St->getMemoryVT().getSizeInBits() + 7) / 8, Unit);
+ // Limit the number of chains to explore, to avoid quadratic compile times.
+ // The limit helps to limit compile time for basic blocks with a large number
+ // of stores.
+ unsigned MaxNumberOfChains = 1000;
while (StoreSDNode *Chain = dyn_cast<StoreSDNode>(STChain->getChain())) {
+ if (!MaxNumberOfChains--)
+ break;
// If the chain has more than one use, then we can't reorder the mem ops.
if (!SDValue(Chain, 0)->hasOneUse())
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61397.197761.patch
Type: text/x-patch
Size: 2926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190502/2b742cc2/attachment.bin>
More information about the llvm-commits
mailing list