[llvm] r312022 - [DAG] Bound loop dependence check in merge optimization.
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 14:40:13 PDT 2017
Merged to 5.0 in r312041.
On Tue, Aug 29, 2017 at 11:41 AM, Hans Wennborg via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: hans
> Date: Tue Aug 29 11:41:00 2017
> New Revision: 312022
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312022&view=rev
> Log:
> [DAG] Bound loop dependence check in merge optimization.
>
> The loop dependence check looks for dependencies between store merge
> candidates not captured by the chain sub-DAG doing a check of
> predecessors which may be very large. Conservatively bound number of
> nodes checked for compilation time. (Resolves PR34326).
>
> Landing on behalf of Nirav Dave to unblock the 5.0.0 release.
>
> Differential Revision: https://reviews.llvm.org/D37220
>
> Modified:
> llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
> llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=312022&r1=312021&r2=312022&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Tue Aug 29 11:41:00 2017
> @@ -799,7 +799,8 @@ public:
> /// if DAG changes.
> static bool hasPredecessorHelper(const SDNode *N,
> SmallPtrSetImpl<const SDNode *> &Visited,
> - SmallVectorImpl<const SDNode *> &Worklist) {
> + SmallVectorImpl<const SDNode *> &Worklist,
> + unsigned int MaxSteps = 0) {
> if (Visited.count(N))
> return true;
> while (!Worklist.empty()) {
> @@ -814,6 +815,8 @@ public:
> }
> if (Found)
> return true;
> + if (MaxSteps != 0 && Visited.size() >= MaxSteps)
> + return false;
> }
> return false;
> }
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=312022&r1=312021&r2=312022&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Aug 29 11:41:00 2017
> @@ -12780,25 +12780,37 @@ void DAGCombiner::getStoreMergeCandidate
> }
> }
>
> -// We need to check that merging these stores does not cause a loop
> -// in the DAG. Any store candidate may depend on another candidate
> +// We need to check that merging these stores does not cause a loop in
> +// the DAG. Any store candidate may depend on another candidate
> // indirectly through its operand (we already consider dependencies
> // through the chain). Check in parallel by searching up from
> // non-chain operands of candidates.
> +
> bool DAGCombiner::checkMergeStoreCandidatesForDependencies(
> SmallVectorImpl<MemOpLink> &StoreNodes, unsigned NumStores) {
> +
> + // FIXME: We should be able to truncate a full search of
> + // predecessors by doing a BFS and keeping tabs the originating
> + // stores from which worklist nodes come from in a similar way to
> + // TokenFactor simplfication.
> +
> SmallPtrSet<const SDNode *, 16> Visited;
> SmallVector<const SDNode *, 8> Worklist;
> - // search ops of store candidates
> + unsigned int Max = 8192;
> + // Search Ops of store candidates.
> for (unsigned i = 0; i < NumStores; ++i) {
> SDNode *n = StoreNodes[i].MemNode;
> // Potential loops may happen only through non-chain operands
> for (unsigned j = 1; j < n->getNumOperands(); ++j)
> Worklist.push_back(n->getOperand(j).getNode());
> }
> - // search through DAG. We can stop early if we find a storenode
> + // Search through DAG. We can stop early if we find a store node.
> for (unsigned i = 0; i < NumStores; ++i) {
> - if (SDNode::hasPredecessorHelper(StoreNodes[i].MemNode, Visited, Worklist))
> + if (SDNode::hasPredecessorHelper(StoreNodes[i].MemNode, Visited, Worklist,
> + Max))
> + return false;
> + // Check if we ended early, failing conservatively if so.
> + if (Visited.size() >= Max)
> return false;
> }
> return true;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list