Delete identity shuffles, implementing CodeGen/Generic/vector-identity-shuffle.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27317 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-03-31 22:16:43 +00:00
parent 9546720484
commit f1d0c623c6

View File

@ -214,6 +214,7 @@ namespace {
SDOperand visitVINSERT_VECTOR_ELT(SDNode *N);
SDOperand visitVBUILD_VECTOR(SDNode *N);
SDOperand visitVECTOR_SHUFFLE(SDNode *N);
SDOperand visitVVECTOR_SHUFFLE(SDNode *N);
SDOperand ReassociateOps(unsigned Opc, SDOperand LHS, SDOperand RHS);
@ -652,6 +653,7 @@ SDOperand DAGCombiner::visit(SDNode *N) {
case ISD::VINSERT_VECTOR_ELT: return visitVINSERT_VECTOR_ELT(N);
case ISD::VBUILD_VECTOR: return visitVBUILD_VECTOR(N);
case ISD::VECTOR_SHUFFLE: return visitVECTOR_SHUFFLE(N);
case ISD::VVECTOR_SHUFFLE: return visitVVECTOR_SHUFFLE(N);
}
return SDOperand();
}
@ -2464,13 +2466,36 @@ SDOperand DAGCombiner::visitVBUILD_VECTOR(SDNode *N) {
}
SDOperand DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
SDOperand ShufMask = N->getOperand(2);
unsigned NumElts = ShufMask.getNumOperands();
// If the shuffle mask is an identity operation on the LHS, return the LHS.
bool isIdentity = true;
for (unsigned i = 0; i != NumElts; ++i) {
if (ShufMask.getOperand(i).getOpcode() != ISD::UNDEF &&
cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() != i) {
isIdentity = false;
break;
}
}
if (isIdentity) return N->getOperand(0);
// If the shuffle mask is an identity operation on the RHS, return the RHS.
isIdentity = true;
for (unsigned i = 0; i != NumElts; ++i) {
if (ShufMask.getOperand(i).getOpcode() != ISD::UNDEF &&
cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() != i+NumElts) {
isIdentity = false;
break;
}
}
if (isIdentity) return N->getOperand(1);
// If the LHS and the RHS are the same node, turn the RHS into an undef.
if (N->getOperand(0) == N->getOperand(1)) {
// Check the SHUFFLE mask, mapping any inputs from the 2nd operand into the
// first operand.
std::vector<SDOperand> MappedOps;
SDOperand ShufMask = N->getOperand(2);
unsigned NumElts = ShufMask.getNumOperands();
for (unsigned i = 0, e = ShufMask.getNumOperands(); i != e; ++i) {
if (cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() >= NumElts) {
unsigned NewIdx =
@ -2491,6 +2516,35 @@ SDOperand DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
return SDOperand();
}
SDOperand DAGCombiner::visitVVECTOR_SHUFFLE(SDNode *N) {
SDOperand ShufMask = N->getOperand(2);
unsigned NumElts = ShufMask.getNumOperands()-2;
// If the shuffle mask is an identity operation on the LHS, return the LHS.
bool isIdentity = true;
for (unsigned i = 0; i != NumElts; ++i) {
if (ShufMask.getOperand(i).getOpcode() != ISD::UNDEF &&
cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() != i) {
isIdentity = false;
break;
}
}
if (isIdentity) return N->getOperand(0);
// If the shuffle mask is an identity operation on the RHS, return the RHS.
isIdentity = true;
for (unsigned i = 0; i != NumElts; ++i) {
if (ShufMask.getOperand(i).getOpcode() != ISD::UNDEF &&
cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() != i+NumElts) {
isIdentity = false;
break;
}
}
if (isIdentity) return N->getOperand(1);
return SDOperand();
}
SDOperand DAGCombiner::SimplifySelect(SDOperand N0, SDOperand N1, SDOperand N2){
assert(N0.getOpcode() ==ISD::SETCC && "First argument must be a SetCC node!");