Revise previous patch per review comments.
[oota-llvm.git] / lib / VMCore / ConstantFold.cpp
index e11b749f9be8f600f381077e224641cce8f474ed..5c80a377ba7b25fecfe65206309ab93b343c69b4 100644 (file)
@@ -87,8 +87,8 @@ static Constant *CastConstantVector(ConstantVector *CV,
     
     if (SrcEltTy->getTypeID() == Type::DoubleTyID) {
       for (unsigned i = 0; i != SrcNumElts; ++i) {
-        uint64_t V = *cast<ConstantFP>(CV->getOperand(i))->
-                       getValueAPF().convertToAPInt().getRawData();
+        uint64_t V = cast<ConstantFP>(CV->getOperand(i))->
+                       getValueAPF().convertToAPInt().getZExtValue();
         Constant *C = ConstantInt::get(Type::Int64Ty, V);
         Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
       }
@@ -97,8 +97,8 @@ static Constant *CastConstantVector(ConstantVector *CV,
 
     assert(SrcEltTy->getTypeID() == Type::FloatTyID);
     for (unsigned i = 0; i != SrcNumElts; ++i) {
-      uint32_t V = (uint32_t)*cast<ConstantFP>(CV->getOperand(i))->
-                               getValueAPF().convertToAPInt().getRawData();
+      uint32_t V = (uint32_t)cast<ConstantFP>(CV->getOperand(i))->
+                               getValueAPF().convertToAPInt().getZExtValue();
       Constant *C = ConstantInt::get(Type::Int32Ty, V);
       Result.push_back(ConstantExpr::getBitCast(C, DstEltTy));
     }
@@ -331,9 +331,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
         return const_cast<Constant*>(V);
 
       if (DestTy->isFloatingPoint()) {
-        if (DestTy == Type::FloatTy)
-          return ConstantFP::get(DestTy, APFloat(CI->getValue()));
-        assert(DestTy == Type::DoubleTy && "Unknown FP type!");
+        assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) && 
+               "Unknown FP type!");
         return ConstantFP::get(DestTy, APFloat(CI->getValue()));
       }
       // Otherwise, can't fold this (vector?)