From f5ed40bd2c80d3414058a1518eb9d6db3031a123 Mon Sep 17 00:00:00 2001 From: Nirav Dave Date: Wed, 2 Aug 2017 01:08:38 +0000 Subject: [PATCH] [DAG] Refactor store merge subexpressions. NFC. Distribute various expressions across ifs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309777 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 51 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index cf19d7b4fc0..59dc714d2ea 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -12445,36 +12445,36 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts( if (NumStores < 2) return false; - int64_t ElementSizeBytes = MemVT.getSizeInBits() / 8; - // The latest Node in the DAG. SDLoc DL(StoreNodes[0].MemNode); - SDValue StoredVal; + int64_t ElementSizeBytes = MemVT.getSizeInBits() / 8; + unsigned SizeInBits = NumStores * ElementSizeBytes * 8; + unsigned NumMemElts = MemVT.isVector() ? MemVT.getVectorNumElements() : 1; + + EVT StoreTy; if (UseVector) { - bool IsVec = MemVT.isVector(); - unsigned Elts = NumStores; - if (IsVec) { - // When merging vector stores, get the total number of elements. - Elts *= MemVT.getVectorNumElements(); - } + unsigned Elts = NumStores * NumMemElts; // Get the type for the merged vector store. - EVT Ty = EVT::getVectorVT(*DAG.getContext(), MemVT.getScalarType(), Elts); - assert(TLI.isTypeLegal(Ty) && "Illegal vector store"); + StoreTy = EVT::getVectorVT(*DAG.getContext(), MemVT.getScalarType(), Elts); + } else + StoreTy = EVT::getIntegerVT(*DAG.getContext(), SizeInBits); + SDValue StoredVal; + if (UseVector) { if (IsConstantSrc) { SmallVector BuildVector; - for (unsigned I = 0, E = Ty.getVectorNumElements(); I != E; ++I) { + for (unsigned I = 0; I != NumStores; ++I) { StoreSDNode *St = cast(StoreNodes[I].MemNode); SDValue Val = St->getValue(); if (MemVT.getScalarType().isInteger()) - if (auto *CFP = dyn_cast(St->getValue())) + if (auto *CFP = dyn_cast(Val)) Val = DAG.getConstant( (uint32_t)CFP->getValueAPF().bitcastToAPInt().getZExtValue(), SDLoc(CFP), MemVT); BuildVector.push_back(Val); } - StoredVal = DAG.getBuildVector(Ty, DL, BuildVector); + StoredVal = DAG.getBuildVector(StoreTy, DL, BuildVector); } else { SmallVector Ops; for (unsigned i = 0; i < NumStores; ++i) { @@ -12487,14 +12487,15 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts( } // Build the extracted vector elements back into a vector. - StoredVal = DAG.getNode(IsVec ? ISD::CONCAT_VECTORS : ISD::BUILD_VECTOR, - DL, Ty, Ops); } + StoredVal = DAG.getNode(MemVT.isVector() ? ISD::CONCAT_VECTORS + : ISD::BUILD_VECTOR, + DL, StoreTy, Ops); + } } else { // We should always use a vector store when merging extracted vector // elements, so this path implies a store of constants. assert(IsConstantSrc && "Merged vector elements should use vector store"); - unsigned SizeInBits = NumStores * ElementSizeBytes * 8; APInt StoreInt(SizeInBits, 0); // Construct a single integer constant which is made of the smaller @@ -12516,7 +12517,6 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts( } // Create the new Load and Store operations. - EVT StoreTy = EVT::getIntegerVT(*DAG.getContext(), SizeInBits); StoredVal = DAG.getConstant(StoreInt, DL, StoreTy); } @@ -12588,12 +12588,10 @@ void DAGCombiner::getStoreMergeCandidates( if (Other->isVolatile() || Other->isIndexed()) return false; SDValue Val = Other->getValue(); - // We can merge constant floats to equivalent integers - if (Other->getMemoryVT() != MemVT) - if (!(MemVT.isInteger() && MemVT.bitsEq(Other->getMemoryVT()) && - isa(Val))) - return false; if (IsLoadSrc) { + // Loads must match type. + if (Other->getMemoryVT() != MemVT) + return false; // The Load's Base Ptr must also match if (LoadSDNode *OtherLd = dyn_cast(Val)) { auto LPtr = BaseIndexOffset::match(OtherLd->getBasePtr(), DAG); @@ -12605,10 +12603,17 @@ void DAGCombiner::getStoreMergeCandidates( return false; } if (IsConstantSrc) { + // Allow merging constants of different types as integers. + if (MemVT.isInteger() ? !MemVT.bitsEq(Other->getMemoryVT()) + : Other->getMemoryVT() != MemVT) + return false; if (!(isa(Val) || isa(Val))) return false; } if (IsExtractVecSrc) { + // Must match type. + if (Other->getMemoryVT() != MemVT) + return false; if (!(Val.getOpcode() == ISD::EXTRACT_VECTOR_ELT || Val.getOpcode() == ISD::EXTRACT_SUBVECTOR)) return false; -- 2.11.0