From f1d0c623c6d9ce3e5d1b30ba3e76e122adc6720e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 31 Mar 2006 22:16:43 +0000 Subject: [PATCH] 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 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 58 +++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 7eeb1003599..86784b7ed06 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -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(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(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 MappedOps; - SDOperand ShufMask = N->getOperand(2); - unsigned NumElts = ShufMask.getNumOperands(); for (unsigned i = 0, e = ShufMask.getNumOperands(); i != e; ++i) { if (cast(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(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(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!");