X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FConstantFold.cpp;h=ff4d897e54a8b945d1d49ff959a424f49452b943;hb=b5bd026a756d8650f2a94607c9b1dc34cf1c024a;hp=0c5297fccb3b8571f2d8c337bb292654358e4041;hpb=c9a005807ab46d03a3b24f84220542c6eb84e9d1;p=oota-llvm.git diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 0c5297fccb3..ff4d897e54a 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -153,26 +153,20 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy) { // Integral -> Integral. This is a no-op because the bit widths must // be the same. Consequently, we just fold to V. return V; - - if (DestTy->isFloatingPoint()) { - assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) && - "Unknown FP type!"); - return ConstantFP::get(APFloat(CI->getValue())); - } + + if (DestTy->isFloatingPoint()) + return ConstantFP::get(APFloat(CI->getValue(), + DestTy != Type::PPC_FP128Ty)); + // Otherwise, can't fold this (vector?) return 0; } - + // Handle ConstantFP input. - if (const ConstantFP *FP = dyn_cast(V)) { + if (const ConstantFP *FP = dyn_cast(V)) // FP -> Integral. - if (DestTy == Type::Int32Ty) { - return ConstantInt::get(FP->getValueAPF().bitcastToAPInt()); - } else { - assert(DestTy == Type::Int64Ty && "only support f32/f64 for now!"); - return ConstantInt::get(FP->getValueAPF().bitcastToAPInt()); - } - } + return ConstantInt::get(FP->getValueAPF().bitcastToAPInt()); + return 0; } @@ -802,16 +796,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, (void)C3V.divide(C2V, APFloat::rmNearestTiesToEven); return ConstantFP::get(C3V); case Instruction::FRem: - if (C2V.isZero()) { - // IEEE 754, Section 7.1, #5 - if (CFP1->getType() == Type::DoubleTy) - return ConstantFP::get(APFloat(std::numeric_limits:: - quiet_NaN())); - if (CFP1->getType() == Type::FloatTy) - return ConstantFP::get(APFloat(std::numeric_limits:: - quiet_NaN())); - break; - } (void)C3V.mod(C2V, APFloat::rmNearestTiesToEven); return ConstantFP::get(C3V); }