Fix some corner cases with vectors in copyToRegs and copyFromRegs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42907 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index d636e8b..c63386c 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -648,7 +648,15 @@
   
     if (MVT::isVector(PartVT)) {
       assert(MVT::isVector(ValueVT) && "Unknown vector conversion!");
-      return DAG.getNode(ISD::BIT_CONVERT, PartVT, Val);
+      return DAG.getNode(ISD::BIT_CONVERT, ValueVT, Val);
+    }
+  
+    if (MVT::isVector(ValueVT)) {
+      assert(NumParts == 1 &&
+             MVT::getVectorElementType(ValueVT) == PartVT &&
+             MVT::getVectorNumElements(ValueVT) == 1 &&
+             "Only trivial scalar-to-vector conversions should get here!");
+      return DAG.getNode(ISD::BUILD_VECTOR, ValueVT, Val);
     }
   
     if (MVT::isInteger(PartVT) &&
@@ -746,6 +754,13 @@
         assert(MVT::isVector(ValueVT) &&
                "Not a vector-vector cast?");
         Val = DAG.getNode(ISD::BIT_CONVERT, PartVT, Val);
+      } else if (MVT::isVector(ValueVT)) {
+        assert(NumParts == 1 &&
+               MVT::getVectorElementType(ValueVT) == PartVT &&
+               MVT::getVectorNumElements(ValueVT) == 1 &&
+               "Only trivial vector-to-scalar conversions should get here!");
+        Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, PartVT, Val,
+                          DAG.getConstant(0, PtrVT));
       } else if (MVT::isInteger(PartVT) && MVT::isInteger(ValueVT)) {
         if (PartVT < ValueVT)
           Val = DAG.getNode(ISD::TRUNCATE, PartVT, Val);