From: Nirav Dave Date: Tue, 11 Apr 2017 13:41:16 +0000 (+0000) Subject: [SDAG] Reorder expensive StoreMerge Check after cheaper one. NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5074c86cc6800e6d9ee23f73feca901b9125b7a7;p=llvm [SDAG] Reorder expensive StoreMerge Check after cheaper one. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299937 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 8f05c61a957..8cb899f2e83 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -468,7 +468,7 @@ namespace { /// Candidate stores have indirect dependency through their /// operands. \return True if safe to merge bool checkMergeStoreCandidatesForDependencies( - SmallVectorImpl &StoreNodes); + SmallVectorImpl &StoreNodes, unsigned NumStores); /// Merge consecutive store operations into a wide store. /// This optimization uses wide integers or vectors when possible. @@ -12287,18 +12287,18 @@ void DAGCombiner::getStoreMergeCandidates( // through the chain). Check in parallel by searching up from // non-chain operands of candidates. bool DAGCombiner::checkMergeStoreCandidatesForDependencies( - SmallVectorImpl &StoreNodes) { + SmallVectorImpl &StoreNodes, unsigned NumStores) { SmallPtrSet Visited; SmallVector Worklist; // search ops of store candidates - for (unsigned i = 0; i < StoreNodes.size(); ++i) { + 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 - for (unsigned i = 0; i < StoreNodes.size(); ++i) { + for (unsigned i = 0; i < NumStores; ++i) { if (SDNode::hasPredecessorHelper(StoreNodes[i].MemNode, Visited, Worklist)) return false; } @@ -12351,10 +12351,6 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode *St) { if (StoreNodes.size() < 2) return false; - // Check that we can merge these candidates without causing a cycle - if (!checkMergeStoreCandidatesForDependencies(StoreNodes)) - return false; - // Sort the memory operands according to their distance from the // base pointer. std::sort(StoreNodes.begin(), StoreNodes.end(), @@ -12379,6 +12375,11 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode *St) { if (NumConsecutiveStores < 2) return false; + // Check that we can merge these candidates without causing a cycle + if (!checkMergeStoreCandidatesForDependencies(StoreNodes, NumConsecutiveStores)) + return false; + + // The node with the lowest store address. LLVMContext &Context = *DAG.getContext(); const DataLayout &DL = DAG.getDataLayout();