EVT LoadResultTy, EVT &ExtVT, EVT &LoadedVT,
bool &NarrowLoad);
+ /// Helper function for MergeConsecutiveStores which merges the
+ /// component store chains.
+ SDValue getMergeStoreChains(SmallVectorImpl<MemOpLink> &StoreNodes,
+ unsigned NumStores);
+
/// This is a helper function for MergeConsecutiveStores. When the source
/// elements of the consecutive stores are all constants or all extracted
/// vector elements, try to merge them into one larger store.
return false;
}
+SDValue DAGCombiner::getMergeStoreChains(SmallVectorImpl<MemOpLink> &StoreNodes,
+ unsigned NumStores) {
+ SmallVector<SDValue, 8> Chains;
+ SmallPtrSet<const SDNode *, 8> Visited;
+ SDLoc StoreDL(StoreNodes[0].MemNode);
+
+ for (unsigned i = 0; i < NumStores; ++i) {
+ Visited.insert(StoreNodes[i].MemNode);
+ }
+
+ // don't include nodes that are children
+ for (unsigned i = 0; i < NumStores; ++i) {
+ if (Visited.count(StoreNodes[i].MemNode->getChain().getNode()) == 0)
+ Chains.push_back(StoreNodes[i].MemNode->getChain());
+ }
+
+ assert(Chains.size() > 0 && "Chain should have generated a chain");
+ return DAG.getNode(ISD::TokenFactor, StoreDL, MVT::Other, Chains);
+}
+
bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
SmallVectorImpl<MemOpLink> &StoreNodes, EVT MemVT,
unsigned NumStores, bool IsConstantSrc, bool UseVector) {
StoredVal = DAG.getConstant(StoreInt, DL, StoreTy);
}
- SmallVector<SDValue, 8> Chains;
-
- // Gather all Chains we're inheriting. As generally all chains are
- // equal, do minor check to remove obvious redundancies.
- Chains.push_back(StoreNodes[0].MemNode->getChain());
- for (unsigned i = 1; i < NumStores; ++i)
- if (StoreNodes[0].MemNode->getChain() != StoreNodes[i].MemNode->getChain())
- Chains.push_back(StoreNodes[i].MemNode->getChain());
-
LSBaseSDNode *FirstInChain = StoreNodes[0].MemNode;
- SDValue NewChain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains);
+ SDValue NewChain = getMergeStoreChains(StoreNodes, NumStores);
SDValue NewStore = DAG.getStore(NewChain, DL, StoredVal,
FirstInChain->getBasePtr(),
FirstInChain->getPointerInfo(),
if (NumElem < 2)
return false;
- // Collect the chains from all merged stores. Because the common case
- // all chains are the same, check if we match the first Chain.
- SmallVector<SDValue, 8> MergeStoreChains;
- MergeStoreChains.push_back(StoreNodes[0].MemNode->getChain());
- for (unsigned i = 1; i < NumElem; ++i)
- if (StoreNodes[0].MemNode->getChain() != StoreNodes[i].MemNode->getChain())
- MergeStoreChains.push_back(StoreNodes[i].MemNode->getChain());
-
// Find if it is better to use vectors or integers to load and store
// to memory.
EVT JointMemOpVT;
FirstLoad->getBasePtr(),
FirstLoad->getPointerInfo(), FirstLoadAlign);
- SDValue NewStoreChain =
- DAG.getNode(ISD::TokenFactor, StoreDL, MVT::Other, MergeStoreChains);
+ SDValue NewStoreChain = getMergeStoreChains(StoreNodes, NumElem);
AddToWorklist(NewStoreChain.getNode());