From 175ac8ea209dbd5b43b9aff79de8725b41f57cd0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 23 Mar 2006 21:16:34 +0000 Subject: [PATCH] add support for splitting casts. This implements CodeGen/Generic/vector.ll:test_cast_2. llvm-svn: 26999 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 42 +++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 0300d336bf6..e864e1894ce 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -4266,7 +4266,7 @@ void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, } switch (Node->getOpcode()) { - default: assert(0 && "Unknown vector operation!"); + default: Node->dump(); assert(0 && "Unknown vector operation!"); case ISD::VBUILD_VECTOR: { std::vector LoOps(Node->op_begin(), Node->op_begin()+NewNumElts); LoOps.push_back(NewNumEltsNode); @@ -4320,6 +4320,46 @@ void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, std::swap(Lo, Hi); break; } + case ISD::VBIT_CONVERT: { + // We know the result is a vector. The input may be either a vector or a + // scalar value. + if (Op.getOperand(0).getValueType() != MVT::Vector) { + // Lower to a store/load. FIXME: this could be improved probably. + SDOperand Ptr = CreateStackTemporary(Op.getOperand(0).getValueType()); + + SDOperand St = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(), + Op.getOperand(0), Ptr, DAG.getSrcValue(0)); + MVT::ValueType EVT = cast(TypeNode)->getVT(); + St = DAG.getVecLoad(NumElements, EVT, St, Ptr, DAG.getSrcValue(0)); + SplitVectorOp(St, Lo, Hi); + } else { + // If the input is a vector type, we have to either scalarize it, pack it + // or convert it based on whether the input vector type is legal. + SDNode *InVal = Node->getOperand(0).Val; + unsigned NumElems = + cast(*(InVal->op_end()-2))->getValue(); + MVT::ValueType EVT = cast(*(InVal->op_end()-1))->getVT(); + + // If the input is from a single element vector, scalarize the vector, + // then treat like a scalar. + if (NumElems == 1) { + SDOperand Scalar = PackVectorOp(Op.getOperand(0), EVT); + Scalar = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, Scalar, + Op.getOperand(1), Op.getOperand(2)); + SplitVectorOp(Scalar, Lo, Hi); + } else { + // Split the input vector. + SplitVectorOp(Op.getOperand(0), Lo, Hi); + + // Convert each of the pieces now. + Lo = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, Lo, + NewNumEltsNode, TypeNode); + Hi = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, Hi, + NewNumEltsNode, TypeNode); + } + break; + } + } } // Remember in a map if the values will be reused later.