diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-20 00:26:06 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-20 00:26:06 +0000 |
commit | eb9c8e1e3fd81607f8aa71f2b8b1592d6d333337 (patch) | |
tree | 7e5b4d1cecbac3a47308900c005c5c8fe5ddd16e /lib/VMCore/ConstantFold.cpp | |
parent | e0db56db311069416159171b6c7a31587ac0af5c (diff) | |
download | external_llvm-eb9c8e1e3fd81607f8aa71f2b8b1592d6d333337.zip external_llvm-eb9c8e1e3fd81607f8aa71f2b8b1592d6d333337.tar.gz external_llvm-eb9c8e1e3fd81607f8aa71f2b8b1592d6d333337.tar.bz2 |
Use simplified ConstantFP::get method, fix a bug handling frem x, 0 with long doubles.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49976 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 353a149..ffc8f02 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -150,7 +150,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy) { if (DestTy->isFloatingPoint()) { assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) && "Unknown FP type!"); - return ConstantFP::get(DestTy, APFloat(CI->getValue())); + return ConstantFP::get(APFloat(CI->getValue())); } // Otherwise, can't fold this (vector?) return 0; @@ -220,7 +220,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, DestTy == Type::FP128Ty ? APFloat::IEEEquad : APFloat::Bogus, APFloat::rmNearestTiesToEven); - return ConstantFP::get(DestTy, Val); + return ConstantFP::get(Val); } return 0; // Can't fold. case Instruction::FPToUI: @@ -262,7 +262,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, (void)apf.convertFromAPInt(api, opc==Instruction::SIToFP, APFloat::rmNearestTiesToEven); - return ConstantFP::get(DestTy, apf); + return ConstantFP::get(apf); } if (const ConstantVector *CV = dyn_cast<ConstantVector>(V)) { std::vector<Constant*> res; @@ -703,30 +703,34 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, APFloat C1V = CFP1->getValueAPF(); APFloat C2V = CFP2->getValueAPF(); APFloat C3V = C1V; // copy for modification - bool isDouble = CFP1->getType()==Type::DoubleTy; switch (Opcode) { default: break; case Instruction::Add: (void)C3V.add(C2V, APFloat::rmNearestTiesToEven); - return ConstantFP::get(CFP1->getType(), C3V); + return ConstantFP::get(C3V); case Instruction::Sub: (void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven); - return ConstantFP::get(CFP1->getType(), C3V); + return ConstantFP::get(C3V); case Instruction::Mul: (void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven); - return ConstantFP::get(CFP1->getType(), C3V); + return ConstantFP::get(C3V); case Instruction::FDiv: (void)C3V.divide(C2V, APFloat::rmNearestTiesToEven); - return ConstantFP::get(CFP1->getType(), C3V); + return ConstantFP::get(C3V); case Instruction::FRem: - if (C2V.isZero()) + if (C2V.isZero()) { // IEEE 754, Section 7.1, #5 - return ConstantFP::get(CFP1->getType(), isDouble ? - APFloat(std::numeric_limits<double>::quiet_NaN()) : - APFloat(std::numeric_limits<float>::quiet_NaN())); + if (CFP1->getType() == Type::DoubleTy) + return ConstantFP::get(APFloat(std::numeric_limits<double>:: + quiet_NaN())); + if (CFP1->getType() == Type::FloatTy) + return ConstantFP::get(APFloat(std::numeric_limits<float>:: + quiet_NaN())); + break; + } (void)C3V.mod(C2V, APFloat::rmNearestTiesToEven); - return ConstantFP::get(CFP1->getType(), C3V); + return ConstantFP::get(C3V); } } } else if (const VectorType *VTy = dyn_cast<VectorType>(C1->getType())) { |