mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-03 15:36:21 +00:00
Clean up code and put transformation on (build_vec (ext x)) into a helper func
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166519 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ce892ca9bc
commit
fac14ab179
@ -270,6 +270,7 @@ namespace {
|
|||||||
SDValue ReduceLoadWidth(SDNode *N);
|
SDValue ReduceLoadWidth(SDNode *N);
|
||||||
SDValue ReduceLoadOpStoreWidth(SDNode *N);
|
SDValue ReduceLoadOpStoreWidth(SDNode *N);
|
||||||
SDValue TransformFPLoadStorePair(SDNode *N);
|
SDValue TransformFPLoadStorePair(SDNode *N);
|
||||||
|
SDValue reduceBuildVecExtToExtBuildVec(SDNode *N);
|
||||||
|
|
||||||
SDValue GetDemandedBits(SDValue V, const APInt &Mask);
|
SDValue GetDemandedBits(SDValue V, const APInt &Mask);
|
||||||
|
|
||||||
@ -8356,15 +8357,21 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
|
|||||||
return SDValue();
|
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();
|
unsigned NumInScalars = N->getNumOperands();
|
||||||
DebugLoc dl = N->getDebugLoc();
|
DebugLoc dl = N->getDebugLoc();
|
||||||
EVT VT = N->getValueType(0);
|
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
|
// 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
|
// 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
|
// 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
|
// 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.
|
// same source type and all of the inputs must be any or zero extend.
|
||||||
// Scalar sizes must be a power of two.
|
// Scalar sizes must be a power of two.
|
||||||
EVT OutScalarTy = N->getValueType(0).getScalarType();
|
EVT OutScalarTy = VT.getScalarType();
|
||||||
bool ValidTypes = SourceType != MVT::Other &&
|
bool ValidTypes = SourceType != MVT::Other &&
|
||||||
isPowerOf2_32(OutScalarTy.getSizeInBits()) &&
|
isPowerOf2_32(OutScalarTy.getSizeInBits()) &&
|
||||||
isPowerOf2_32(SourceType.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
|
// Create a new simpler BUILD_VECTOR sequence which other optimizations can
|
||||||
// turn into a single shuffle instruction.
|
// turn into a single shuffle instruction.
|
||||||
if ((Level == AfterLegalizeVectorOps || Level == AfterLegalizeTypes) &&
|
if (!ValidTypes)
|
||||||
ValidTypes) {
|
return SDValue();
|
||||||
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);
|
|
||||||
|
|
||||||
unsigned NewBVElems = ElemRatio * N->getValueType(0).getVectorNumElements();
|
bool isLE = TLI.isLittleEndian();
|
||||||
SmallVector<SDValue, 8> Ops(NewBVElems, Filler);
|
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
|
unsigned NewBVElems = ElemRatio * VT.getVectorNumElements();
|
||||||
for (unsigned i=0; i < N->getNumOperands(); ++i) {
|
SmallVector<SDValue, 8> Ops(NewBVElems, Filler);
|
||||||
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));
|
|
||||||
|
|
||||||
assert(Index < Ops.size() && "Invalid index");
|
// Populate the new build_vector
|
||||||
Ops[Index] = In;
|
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.
|
assert(Index < Ops.size() && "Invalid index");
|
||||||
EVT VecVT = EVT::getVectorVT(*DAG.getContext(), SourceType, NewBVElems);
|
Ops[Index] = In;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// 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
|
// operations. If so, and if the EXTRACT_VECTOR_ELT vector inputs come from
|
||||||
// at most two distinct vectors, turn this into a shuffle node.
|
// at most two distinct vectors, turn this into a shuffle node.
|
||||||
@ -8549,7 +8563,7 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
|||||||
return SDValue();
|
return SDValue();
|
||||||
|
|
||||||
// Widen the input vector by adding undef values.
|
// 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()));
|
VecIn1, DAG.getUNDEF(VecIn1.getValueType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8570,7 +8584,7 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
|
|||||||
SDValue Ops[2];
|
SDValue Ops[2];
|
||||||
Ops[0] = VecIn1;
|
Ops[0] = VecIn1;
|
||||||
Ops[1] = VecIn2;
|
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();
|
return SDValue();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user