- double d = CI->getValue().signedRoundToDouble();
- if (DestTy==Type::FloatTy)
- return ConstantFP::get(DestTy, APFloat((float)d));
- else if (DestTy==Type::DoubleTy)
- return ConstantFP::get(DestTy, APFloat(d));
- else
- return 0; // FIXME do this for long double
+ APInt api = CI->getValue();
+ const uint64_t zero[] = {0, 0};
+ uint32_t BitWidth = cast<IntegerType>(SrcTy)->getBitWidth();
+ APFloat apf = APFloat(APInt(DestTy->getPrimitiveSizeInBits(),
+ 2, zero));
+ (void)apf.convertFromInteger(api.getRawData(), BitWidth,
+ opc==Instruction::SIToFP,
+ APFloat::rmNearestTiesToEven);
+ return ConstantFP::get(DestTy, apf);