mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
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
This commit is contained in:
parent
e0db56db31
commit
eb9c8e1e3f
@ -150,7 +150,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy) {
|
|||||||
if (DestTy->isFloatingPoint()) {
|
if (DestTy->isFloatingPoint()) {
|
||||||
assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) &&
|
assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) &&
|
||||||
"Unknown FP type!");
|
"Unknown FP type!");
|
||||||
return ConstantFP::get(DestTy, APFloat(CI->getValue()));
|
return ConstantFP::get(APFloat(CI->getValue()));
|
||||||
}
|
}
|
||||||
// Otherwise, can't fold this (vector?)
|
// Otherwise, can't fold this (vector?)
|
||||||
return 0;
|
return 0;
|
||||||
@ -220,7 +220,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
|
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
|
||||||
APFloat::Bogus,
|
APFloat::Bogus,
|
||||||
APFloat::rmNearestTiesToEven);
|
APFloat::rmNearestTiesToEven);
|
||||||
return ConstantFP::get(DestTy, Val);
|
return ConstantFP::get(Val);
|
||||||
}
|
}
|
||||||
return 0; // Can't fold.
|
return 0; // Can't fold.
|
||||||
case Instruction::FPToUI:
|
case Instruction::FPToUI:
|
||||||
@ -262,7 +262,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
(void)apf.convertFromAPInt(api,
|
(void)apf.convertFromAPInt(api,
|
||||||
opc==Instruction::SIToFP,
|
opc==Instruction::SIToFP,
|
||||||
APFloat::rmNearestTiesToEven);
|
APFloat::rmNearestTiesToEven);
|
||||||
return ConstantFP::get(DestTy, apf);
|
return ConstantFP::get(apf);
|
||||||
}
|
}
|
||||||
if (const ConstantVector *CV = dyn_cast<ConstantVector>(V)) {
|
if (const ConstantVector *CV = dyn_cast<ConstantVector>(V)) {
|
||||||
std::vector<Constant*> res;
|
std::vector<Constant*> res;
|
||||||
@ -703,30 +703,34 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
|
|||||||
APFloat C1V = CFP1->getValueAPF();
|
APFloat C1V = CFP1->getValueAPF();
|
||||||
APFloat C2V = CFP2->getValueAPF();
|
APFloat C2V = CFP2->getValueAPF();
|
||||||
APFloat C3V = C1V; // copy for modification
|
APFloat C3V = C1V; // copy for modification
|
||||||
bool isDouble = CFP1->getType()==Type::DoubleTy;
|
|
||||||
switch (Opcode) {
|
switch (Opcode) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return ConstantFP::get(CFP1->getType(), C3V);
|
return ConstantFP::get(C3V);
|
||||||
case Instruction::Sub:
|
case Instruction::Sub:
|
||||||
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return ConstantFP::get(CFP1->getType(), C3V);
|
return ConstantFP::get(C3V);
|
||||||
case Instruction::Mul:
|
case Instruction::Mul:
|
||||||
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return ConstantFP::get(CFP1->getType(), C3V);
|
return ConstantFP::get(C3V);
|
||||||
case Instruction::FDiv:
|
case Instruction::FDiv:
|
||||||
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
|
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
|
||||||
return ConstantFP::get(CFP1->getType(), C3V);
|
return ConstantFP::get(C3V);
|
||||||
case Instruction::FRem:
|
case Instruction::FRem:
|
||||||
if (C2V.isZero())
|
if (C2V.isZero()) {
|
||||||
// IEEE 754, Section 7.1, #5
|
// IEEE 754, Section 7.1, #5
|
||||||
return ConstantFP::get(CFP1->getType(), isDouble ?
|
if (CFP1->getType() == Type::DoubleTy)
|
||||||
APFloat(std::numeric_limits<double>::quiet_NaN()) :
|
return ConstantFP::get(APFloat(std::numeric_limits<double>::
|
||||||
APFloat(std::numeric_limits<float>::quiet_NaN()));
|
quiet_NaN()));
|
||||||
|
if (CFP1->getType() == Type::FloatTy)
|
||||||
|
return ConstantFP::get(APFloat(std::numeric_limits<float>::
|
||||||
|
quiet_NaN()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
(void)C3V.mod(C2V, APFloat::rmNearestTiesToEven);
|
(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())) {
|
} else if (const VectorType *VTy = dyn_cast<VectorType>(C1->getType())) {
|
||||||
|
@ -307,12 +307,11 @@ static const fltSemantics &SemanticsForType(Type *Ty) {
|
|||||||
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
|
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
|
||||||
APFloat APN(N);
|
APFloat APN(N);
|
||||||
APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven);
|
APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven);
|
||||||
return wrap(ConstantFP::get(unwrap(RealTy), APN));
|
return wrap(ConstantFP::get(APN));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
|
LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
|
||||||
return wrap(ConstantFP::get(unwrap(RealTy),
|
return wrap(ConstantFP::get(APFloat(SemanticsForType(unwrap(RealTy)), Text)));
|
||||||
APFloat(SemanticsForType(unwrap(RealTy)), Text)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--.. Operations on composite constants ...................................--*/
|
/*--.. Operations on composite constants ...................................--*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user