Fix PR3899: add support for extracting floats from vectors
authorDuncan Sands <baldrick@free.fr>
Sun, 29 Mar 2009 13:51:06 +0000 (13:51 +0000)
committerDuncan Sands <baldrick@free.fr>
Sun, 29 Mar 2009 13:51:06 +0000 (13:51 +0000)
when using -soft-float.
Based on a patch by Jakob Stoklund Olesen.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67996 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
lib/CodeGen/SelectionDAG/LegalizeTypes.h
test/CodeGen/Generic/2009-03-29-SoftFloatVectorExtract.ll [new file with mode: 0644]

index ce312ae8c86ab05af0dba65c2641c5c243de51a5..8aa3e940025a9dcf43cf34a4dca3093ac2e2fb65 100644 (file)
@@ -59,6 +59,8 @@ void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
     case ISD::ConstantFP:
       R = SoftenFloatRes_ConstantFP(cast<ConstantFPSDNode>(N));
       break;
+    case ISD::EXTRACT_VECTOR_ELT:
+      R = SoftenFloatRes_EXTRACT_VECTOR_ELT(N); break;
     case ISD::FABS:        R = SoftenFloatRes_FABS(N); break;
     case ISD::FADD:        R = SoftenFloatRes_FADD(N); break;
     case ISD::FCEIL:       R = SoftenFloatRes_FCEIL(N); break;
@@ -113,6 +115,13 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_ConstantFP(ConstantFPSDNode *N) {
                          TLI.getTypeToTransformTo(N->getValueType(0)));
 }
 
+SDValue DAGTypeLegalizer::SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N) {
+  SDValue NewOp = BitConvertVectorToIntegerVector(N->getOperand(0));
+  return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, N->getDebugLoc(),
+                     NewOp.getValueType().getVectorElementType(),
+                     NewOp, N->getOperand(1));
+}
+
 SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
   MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0));
   unsigned Size = NVT.getSizeInBits();
index 28f7a4db9ca25c96fd8e6a71bafb875a35c68220..985d345956710662cc5ca19106977c1b395370da 100644 (file)
@@ -858,6 +858,17 @@ SDValue DAGTypeLegalizer::BitConvertToInteger(SDValue Op) {
                      MVT::getIntegerVT(BitWidth), Op);
 }
 
+/// BitConvertVectorToIntegerVector - Convert to a vector of integers of the
+/// same size.
+SDValue DAGTypeLegalizer::BitConvertVectorToIntegerVector(SDValue Op) {
+  assert(Op.getValueType().isVector() && "Only applies to vectors!");
+  unsigned EltWidth = Op.getValueType().getVectorElementType().getSizeInBits();
+  MVT EltNVT = MVT::getIntegerVT(EltWidth);
+  unsigned NumElts = Op.getValueType().getVectorNumElements();
+  return DAG.getNode(ISD::BIT_CONVERT, Op.getDebugLoc(),
+                     MVT::getVectorVT(EltNVT, NumElts), Op);
+}
+
 SDValue DAGTypeLegalizer::CreateStackStoreLoad(SDValue Op,
                                                MVT DestVT) {
   DebugLoc dl = Op.getDebugLoc();
index 0cceafc0b0a1630b3d919593a237b6cd652ee523..25fa4a70d4ae662385771ffb341dedd7c2fc383a 100644 (file)
@@ -190,6 +190,7 @@ private:
 
   // Common routines.
   SDValue BitConvertToInteger(SDValue Op);
+  SDValue BitConvertVectorToIntegerVector(SDValue Op);
   SDValue CreateStackStoreLoad(SDValue Op, MVT DestVT);
   bool CustomLowerResults(SDNode *N, MVT VT, bool LegalizeResult);
   SDValue GetVectorElementPointer(SDValue VecPtr, MVT EltVT, SDValue Index);
@@ -392,6 +393,7 @@ private:
   SDValue SoftenFloatRes_BIT_CONVERT(SDNode *N);
   SDValue SoftenFloatRes_BUILD_PAIR(SDNode *N);
   SDValue SoftenFloatRes_ConstantFP(ConstantFPSDNode *N);
+  SDValue SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N);
   SDValue SoftenFloatRes_FABS(SDNode *N);
   SDValue SoftenFloatRes_FADD(SDNode *N);
   SDValue SoftenFloatRes_FCEIL(SDNode *N);
diff --git a/test/CodeGen/Generic/2009-03-29-SoftFloatVectorExtract.ll b/test/CodeGen/Generic/2009-03-29-SoftFloatVectorExtract.ll
new file mode 100644 (file)
index 0000000..40ad3de
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | llc -soft-float
+; PR3899
+
+@m = external global <2 x double>;
+
+define double @vector_ex() nounwind {
+       %v = load <2 x double>* @m
+       %x = extractelement <2 x double> %v, i32 1
+       ret double %x
+}