aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-09-30 18:19:03 +0000
committerDale Johannesen <dalej@apple.com>2007-09-30 18:19:03 +0000
commit87fa68f68eb00accc7cd87ef0e8df0a53f3d6ee9 (patch)
treedb3b24ea0faceec5eb021615d89bf25953be1076
parente96fcea579a91a8b06fce5bd9be3054830dc5be5 (diff)
downloadexternal_llvm-87fa68f68eb00accc7cd87ef0e8df0a53f3d6ee9.zip
external_llvm-87fa68f68eb00accc7cd87ef0e8df0a53f3d6ee9.tar.gz
external_llvm-87fa68f68eb00accc7cd87ef0e8df0a53f3d6ee9.tar.bz2
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42484 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp2
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp2
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp4
-rw-r--r--lib/VMCore/ConstantFold.cpp26
4 files changed, 13 insertions, 21 deletions
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 2fc8b0a..7f2b6e7 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -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);
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 042868d..e286eb0 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -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:
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index c72663e..61be350 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -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;
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 73ca47a..72077db 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -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: