[llvm-commits] [llvm] r42484 - in /llvm/trunk/lib: CodeGen/SelectionDAG/LegalizeDAG.cpp CodeGen/SelectionDAG/SelectionDAG.cpp ExecutionEngine/ExecutionEngine.cpp VMCore/ConstantFold.cpp
Dale Johannesen
dalej at apple.com
Sun Sep 30 11:19:03 PDT 2007
Author: johannes
Date: Sun Sep 30 13:19:03 2007
New Revision: 42484
URL: http://llvm.org/viewvc/llvm-project?rev=42484&view=rev
Log:
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).
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
llvm/trunk/lib/VMCore/ConstantFold.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=42484&r1=42483&r2=42484&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Sun Sep 30 13:19:03 2007
@@ -3220,7 +3220,7 @@
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);
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=42484&r1=42483&r2=42484&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sun Sep 30 13:19:03 2007
@@ -1598,7 +1598,7 @@
(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:
Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=42484&r1=42483&r2=42484&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Sun Sep 30 13:19:03 2007
@@ -398,7 +398,7 @@
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 @@
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;
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=42484&r1=42483&r2=42484&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Sun Sep 30 13:19:03 2007
@@ -209,25 +209,17 @@
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:
More information about the llvm-commits
mailing list