From: Evan Cheng Date: Wed, 5 Apr 2006 06:07:11 +0000 (+0000) Subject: Exapnd a VECTOR_SHUFFLE to a BUILD_VECTOR if target asks for it to be expanded X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=18dd6d0a2aeb3b827391f46996a7b40c9b1f907a;p=oota-llvm.git Exapnd a VECTOR_SHUFFLE to a BUILD_VECTOR if target asks for it to be expanded or custom lowering fails. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27432 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 1d624dbc147..b0d0b37aa64 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -933,9 +933,37 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { "vector shuffle should not be created if not legal!"); break; case TargetLowering::Custom: - Tmp1 = TLI.LowerOperation(Result, DAG); - if (Tmp1.Val) Result = Tmp1; + Tmp3 = TLI.LowerOperation(Result, DAG); + if (Tmp3.Val) { + Result = Tmp3; + break; + } + // FALLTHROUGH + case TargetLowering::Expand: { + MVT::ValueType VT = Node->getValueType(0); + MVT::ValueType EltVT = MVT::getVectorBaseType(VT); + MVT::ValueType PtrVT = TLI.getPointerTy(); + SDOperand Mask = Node->getOperand(2); + unsigned NumElems = Mask.getNumOperands(); + std::vector Ops; + for (unsigned i = 0; i != NumElems; ++i) { + SDOperand Arg = Mask.getOperand(i); + if (Arg.getOpcode() == ISD::UNDEF) { + Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); + } else { + assert(isa(Arg) && "Invalid VECTOR_SHUFFLE mask!"); + unsigned Idx = cast(Arg)->getValue(); + if (Idx < NumElems) + Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, + DAG.getConstant(Idx, PtrVT))); + else + Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, + DAG.getConstant(Idx - NumElems, PtrVT))); + } + } + Result = DAG.getNode(ISD::BUILD_VECTOR, VT, Ops); break; + } case TargetLowering::Promote: { // Change base type to a different vector type. MVT::ValueType OVT = Node->getValueType(0);