forked from OSchip/llvm-project
Clean up code and put transformation on (build_vec (ext x)) into a helper func
llvm-svn: 166519
This commit is contained in:
parent
6f5309cf50
commit
6d106b7bfd
|
@ -270,6 +270,7 @@ namespace {
|
|||
SDValue ReduceLoadWidth(SDNode *N);
|
||||
SDValue ReduceLoadOpStoreWidth(SDNode *N);
|
||||
SDValue TransformFPLoadStorePair(SDNode *N);
|
||||
SDValue reduceBuildVecExtToExtBuildVec(SDNode *N);
|
||||
|
||||
SDValue GetDemandedBits(SDValue V, const APInt &Mask);
|
||||
|
||||
|
@ -8356,15 +8357,21 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
|
|||
return SDValue();
|
||||
}
|
||||
|
||||
SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
||||
// Simplify (build_vec (ext )) to (bitcast (build_vec ))
|
||||
SDValue DAGCombiner::reduceBuildVecExtToExtBuildVec(SDNode *N) {
|
||||
// We perform this optimization post type-legalization because
|
||||
// the type-legalizer often scalarizes integer-promoted vectors.
|
||||
// Performing this optimization before may create bit-casts which
|
||||
// will be type-legalized to complex code sequences.
|
||||
// We perform this optimization only before the operation legalizer because we
|
||||
// may introduce illegal operations.
|
||||
if (Level != AfterLegalizeVectorOps && Level != AfterLegalizeTypes)
|
||||
return SDValue();
|
||||
|
||||
unsigned NumInScalars = N->getNumOperands();
|
||||
DebugLoc dl = N->getDebugLoc();
|
||||
EVT VT = N->getValueType(0);
|
||||
|
||||
// A vector built entirely of undefs is undef.
|
||||
if (ISD::allOperandsUndef(N))
|
||||
return DAG.getUNDEF(VT);
|
||||
|
||||
// Check to see if this is a BUILD_VECTOR of a bunch of values
|
||||
// which come from any_extend or zero_extend nodes. If so, we can create
|
||||
// a new BUILD_VECTOR using bit-casts which may enable other BUILD_VECTOR
|
||||
|
@ -8407,65 +8414,72 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
|||
// In order to have valid types, all of the inputs must be extended from the
|
||||
// same source type and all of the inputs must be any or zero extend.
|
||||
// Scalar sizes must be a power of two.
|
||||
EVT OutScalarTy = N->getValueType(0).getScalarType();
|
||||
EVT OutScalarTy = VT.getScalarType();
|
||||
bool ValidTypes = SourceType != MVT::Other &&
|
||||
isPowerOf2_32(OutScalarTy.getSizeInBits()) &&
|
||||
isPowerOf2_32(SourceType.getSizeInBits());
|
||||
|
||||
// We perform this optimization post type-legalization because
|
||||
// the type-legalizer often scalarizes integer-promoted vectors.
|
||||
// Performing this optimization before may create bit-casts which
|
||||
// will be type-legalized to complex code sequences.
|
||||
// We perform this optimization only before the operation legalizer because we
|
||||
// may introduce illegal operations.
|
||||
// Create a new simpler BUILD_VECTOR sequence which other optimizations can
|
||||
// turn into a single shuffle instruction.
|
||||
if ((Level == AfterLegalizeVectorOps || Level == AfterLegalizeTypes) &&
|
||||
ValidTypes) {
|
||||
bool isLE = TLI.isLittleEndian();
|
||||
unsigned ElemRatio = OutScalarTy.getSizeInBits()/SourceType.getSizeInBits();
|
||||
assert(ElemRatio > 1 && "Invalid element size ratio");
|
||||
SDValue Filler = AllAnyExt ? DAG.getUNDEF(SourceType):
|
||||
DAG.getConstant(0, SourceType);
|
||||
if (!ValidTypes)
|
||||
return SDValue();
|
||||
|
||||
unsigned NewBVElems = ElemRatio * N->getValueType(0).getVectorNumElements();
|
||||
SmallVector<SDValue, 8> Ops(NewBVElems, Filler);
|
||||
bool isLE = TLI.isLittleEndian();
|
||||
unsigned ElemRatio = OutScalarTy.getSizeInBits()/SourceType.getSizeInBits();
|
||||
assert(ElemRatio > 1 && "Invalid element size ratio");
|
||||
SDValue Filler = AllAnyExt ? DAG.getUNDEF(SourceType):
|
||||
DAG.getConstant(0, SourceType);
|
||||
|
||||
// Populate the new build_vector
|
||||
for (unsigned i=0; i < N->getNumOperands(); ++i) {
|
||||
SDValue Cast = N->getOperand(i);
|
||||
assert((Cast.getOpcode() == ISD::ANY_EXTEND ||
|
||||
Cast.getOpcode() == ISD::ZERO_EXTEND ||
|
||||
Cast.getOpcode() == ISD::UNDEF) && "Invalid cast opcode");
|
||||
SDValue In;
|
||||
if (Cast.getOpcode() == ISD::UNDEF)
|
||||
In = DAG.getUNDEF(SourceType);
|
||||
else
|
||||
In = Cast->getOperand(0);
|
||||
unsigned Index = isLE ? (i * ElemRatio) :
|
||||
(i * ElemRatio + (ElemRatio - 1));
|
||||
unsigned NewBVElems = ElemRatio * VT.getVectorNumElements();
|
||||
SmallVector<SDValue, 8> Ops(NewBVElems, Filler);
|
||||
|
||||
assert(Index < Ops.size() && "Invalid index");
|
||||
Ops[Index] = In;
|
||||
}
|
||||
// Populate the new build_vector
|
||||
for (unsigned i=0; i < N->getNumOperands(); ++i) {
|
||||
SDValue Cast = N->getOperand(i);
|
||||
assert((Cast.getOpcode() == ISD::ANY_EXTEND ||
|
||||
Cast.getOpcode() == ISD::ZERO_EXTEND ||
|
||||
Cast.getOpcode() == ISD::UNDEF) && "Invalid cast opcode");
|
||||
SDValue In;
|
||||
if (Cast.getOpcode() == ISD::UNDEF)
|
||||
In = DAG.getUNDEF(SourceType);
|
||||
else
|
||||
In = Cast->getOperand(0);
|
||||
unsigned Index = isLE ? (i * ElemRatio) :
|
||||
(i * ElemRatio + (ElemRatio - 1));
|
||||
|
||||
// The type of the new BUILD_VECTOR node.
|
||||
EVT VecVT = EVT::getVectorVT(*DAG.getContext(), SourceType, NewBVElems);
|
||||
assert(VecVT.getSizeInBits() == N->getValueType(0).getSizeInBits() &&
|
||||
"Invalid vector size");
|
||||
// Check if the new vector type is legal.
|
||||
if (!isTypeLegal(VecVT)) return SDValue();
|
||||
|
||||
// Make the new BUILD_VECTOR.
|
||||
SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(),
|
||||
VecVT, &Ops[0], Ops.size());
|
||||
|
||||
// The new BUILD_VECTOR node has the potential to be further optimized.
|
||||
AddToWorkList(BV.getNode());
|
||||
// Bitcast to the desired type.
|
||||
return DAG.getNode(ISD::BITCAST, dl, N->getValueType(0), BV);
|
||||
assert(Index < Ops.size() && "Invalid index");
|
||||
Ops[Index] = In;
|
||||
}
|
||||
|
||||
// The type of the new BUILD_VECTOR node.
|
||||
EVT VecVT = EVT::getVectorVT(*DAG.getContext(), SourceType, NewBVElems);
|
||||
assert(VecVT.getSizeInBits() == VT.getSizeInBits() &&
|
||||
"Invalid vector size");
|
||||
// Check if the new vector type is legal.
|
||||
if (!isTypeLegal(VecVT)) return SDValue();
|
||||
|
||||
// Make the new BUILD_VECTOR.
|
||||
SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], Ops.size());
|
||||
|
||||
// The new BUILD_VECTOR node has the potential to be further optimized.
|
||||
AddToWorkList(BV.getNode());
|
||||
// Bitcast to the desired type.
|
||||
return DAG.getNode(ISD::BITCAST, dl, VT, BV);
|
||||
}
|
||||
|
||||
SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
||||
unsigned NumInScalars = N->getNumOperands();
|
||||
DebugLoc dl = N->getDebugLoc();
|
||||
EVT VT = N->getValueType(0);
|
||||
|
||||
// A vector built entirely of undefs is undef.
|
||||
if (ISD::allOperandsUndef(N))
|
||||
return DAG.getUNDEF(VT);
|
||||
|
||||
SDValue V = reduceBuildVecExtToExtBuildVec(N);
|
||||
if (V.getNode())
|
||||
return V;
|
||||
|
||||
// Check to see if this is a BUILD_VECTOR of a bunch of EXTRACT_VECTOR_ELT
|
||||
// operations. If so, and if the EXTRACT_VECTOR_ELT vector inputs come from
|
||||
// at most two distinct vectors, turn this into a shuffle node.
|
||||
|
@ -8549,7 +8563,7 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
|||
return SDValue();
|
||||
|
||||
// Widen the input vector by adding undef values.
|
||||
VecIn1 = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT,
|
||||
VecIn1 = DAG.getNode(ISD::CONCAT_VECTORS, dl, VT,
|
||||
VecIn1, DAG.getUNDEF(VecIn1.getValueType()));
|
||||
}
|
||||
|
||||
|
@ -8570,7 +8584,7 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
|||
SDValue Ops[2];
|
||||
Ops[0] = VecIn1;
|
||||
Ops[1] = VecIn2;
|
||||
return DAG.getVectorShuffle(VT, N->getDebugLoc(), Ops[0], Ops[1], &Mask[0]);
|
||||
return DAG.getVectorShuffle(VT, dl, Ops[0], Ops[1], &Mask[0]);
|
||||
}
|
||||
|
||||
return SDValue();
|
||||
|
|
Loading…
Reference in New Issue