[PATCH] D54517: [CGP] Limit Complex Addressing mode by number of BasicBlocks to traverse
Serguei Katkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 14 01:54:18 PST 2018
skatkov created this revision.
skatkov added reviewers: john.brawn, reames, bjope.
The finding the combined complex addressing mode in some cases becomes
expensive. This CL limits the work by number of basic blocks to traverse.
This is a fix for PR39625.
https://reviews.llvm.org/D54517
Files:
lib/CodeGen/CodeGenPrepare.cpp
Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -192,6 +192,11 @@
cl::desc("Disables combining addressing modes with different parts "
"in optimizeMemoryInst."));
+static cl::opt<int> ComplexAddrModesThreshold(
+ "complex-addr-modes-threshold", cl::Hidden, cl::init(100),
+ cl::desc("Stop processing complex addressing mode optimization"
+ " if number of basic blocks to process exceeds threshold"));
+
static cl::opt<bool>
AddrSinkNewPhis("addr-sink-new-phis", cl::Hidden, cl::init(false),
cl::desc("Allow creation of Phis in Address sinking."));
@@ -3084,7 +3089,13 @@
// First step, DFS to create PHI nodes for all intermediate blocks.
// Also fill traverse order for the second step.
SmallVector<ValueInBB, 32> TraverseOrder;
- InsertPlaceholders(Map, TraverseOrder, ST);
+ if (!InsertPlaceholders(Map, TraverseOrder, ST)) {
+ LLVM_DEBUG(
+ dbgs() << "Stop complex addressing mode due to exceed of threshold: "
+ << TraverseOrder.size());
+ ST.destroyNewNodes(CommonType);
+ return nullptr;
+ }
// Second Step, fill new nodes by merged values and simplify if possible.
FillPlaceholders(Map, TraverseOrder, ST);
@@ -3258,7 +3269,8 @@
/// a placeholder Phi or Select.
/// Reports all new created Phi/Select nodes by adding them to set.
/// Also reports and order in what basic blocks have been traversed.
- void InsertPlaceholders(FoldAddrToValueMapping &Map,
+ /// Return false if size of TraverseOrder exceeds threshold.
+ bool InsertPlaceholders(FoldAddrToValueMapping &Map,
SmallVectorImpl<ValueInBB> &TraverseOrder,
SimplificationTracker &ST) {
SmallVector<ValueInBB, 32> Worklist;
@@ -3278,6 +3290,8 @@
if (Map.find(Current) != Map.end())
continue;
TraverseOrder.push_back(Current);
+ if ((int)TraverseOrder.size() > ComplexAddrModesThreshold)
+ return false;
Value *CurrentValue = Current.first;
BasicBlock *CurrentBlock = Current.second;
@@ -3327,6 +3341,7 @@
Worklist.push_back({ CurrentPhi->getIncomingValueForBlock(B), B });
}
}
+ return true;
}
bool addrModeCombiningAllowed() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54517.174001.patch
Type: text/x-patch
Size: 2414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181114/218c9b68/attachment.bin>
More information about the llvm-commits
mailing list