forked from OSchip/llvm-project
Constant fold int-to-long-double conversions;
use APFloat for int-to-float/double; use round-to-nearest for these (implementation-defined, seems to match gcc). llvm-svn: 42484
This commit is contained in:
parent
28a2c4a9c4
commit
9150652b21
|
@ -3220,7 +3220,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
|
|||
APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
|
||||
uint64_t x = 1ULL << ShiftAmt;
|
||||
(void)apf.convertFromInteger(&x, MVT::getSizeInBits(NVT), false,
|
||||
APFloat::rmTowardZero);
|
||||
APFloat::rmNearestTiesToEven);
|
||||
Tmp2 = DAG.getConstantFP(apf, VT);
|
||||
Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(),
|
||||
Node->getOperand(0), Tmp2, ISD::SETLT);
|
||||
|
|
|
@ -1598,7 +1598,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
|
|||
(void)apf.convertFromInteger(&Val,
|
||||
MVT::getSizeInBits(Operand.getValueType()),
|
||||
Opcode==ISD::SINT_TO_FP,
|
||||
APFloat::rmTowardZero);
|
||||
APFloat::rmNearestTiesToEven);
|
||||
return getConstantFP(apf, VT);
|
||||
}
|
||||
case ISD::BIT_CONVERT:
|
||||
|
|
|
@ -398,7 +398,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
|||
APFloat apf = APFloat(APInt(80, 2, zero));
|
||||
(void)apf.convertFromInteger(GV.IntVal.getRawData(),
|
||||
GV.IntVal.getBitWidth(), false,
|
||||
APFloat::rmTowardZero);
|
||||
APFloat::rmNearestTiesToEven);
|
||||
GV.IntVal = apf.convertToAPInt();
|
||||
}
|
||||
return GV;
|
||||
|
@ -414,7 +414,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
|||
APFloat apf = APFloat(APInt(80, 2, zero));
|
||||
(void)apf.convertFromInteger(GV.IntVal.getRawData(),
|
||||
GV.IntVal.getBitWidth(), true,
|
||||
APFloat::rmTowardZero);
|
||||
APFloat::rmNearestTiesToEven);
|
||||
GV.IntVal = apf.convertToAPInt();
|
||||
}
|
||||
return GV;
|
||||
|
|
|
@ -209,25 +209,17 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||
return ConstantInt::get(DestTy, 0);
|
||||
return 0; // Other pointer types cannot be casted
|
||||
case Instruction::UIToFP:
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
|
||||
double d = CI->getValue().roundToDouble();
|
||||
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
|
||||
}
|
||||
return 0;
|
||||
case Instruction::SIToFP:
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::ZExt:
|
||||
|
|
Loading…
Reference in New Issue