Skip to content

Commit

Permalink
[DAG] Refactor store merge subexpressions. NFC.
Browse files Browse the repository at this point in the history
Distribute various expressions across ifs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309777 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
niravhdave committed Aug 2, 2017
1 parent 01ddaaf commit f5ed40b
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SDValue, 8> BuildVector;
for (unsigned I = 0, E = Ty.getVectorNumElements(); I != E; ++I) {
for (unsigned I = 0; I != NumStores; ++I) {
StoreSDNode *St = cast<StoreSDNode>(StoreNodes[I].MemNode);
SDValue Val = St->getValue();
if (MemVT.getScalarType().isInteger())
if (auto *CFP = dyn_cast<ConstantFPSDNode>(St->getValue()))
if (auto *CFP = dyn_cast<ConstantFPSDNode>(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<SDValue, 8> Ops;
for (unsigned i = 0; i < NumStores; ++i) {
Expand All @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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<ConstantFPSDNode>(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<LoadSDNode>(Val)) {
auto LPtr = BaseIndexOffset::match(OtherLd->getBasePtr(), DAG);
Expand All @@ -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<ConstantSDNode>(Val) || isa<ConstantFPSDNode>(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;
Expand Down

0 comments on commit f5ed40b

Please sign in to comment.