mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-06 21:27:23 +00:00
FP16 constfolding
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98911 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -994,6 +994,8 @@ llvm::canConstantFoldCallTo(const Function *F) {
|
|||||||
case Intrinsic::usub_with_overflow:
|
case Intrinsic::usub_with_overflow:
|
||||||
case Intrinsic::sadd_with_overflow:
|
case Intrinsic::sadd_with_overflow:
|
||||||
case Intrinsic::ssub_with_overflow:
|
case Intrinsic::ssub_with_overflow:
|
||||||
|
case Intrinsic::convert_from_fp16:
|
||||||
|
case Intrinsic::convert_to_fp16:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@@ -1074,6 +1076,15 @@ llvm::ConstantFoldCall(Function *F,
|
|||||||
const Type *Ty = F->getReturnType();
|
const Type *Ty = F->getReturnType();
|
||||||
if (NumOperands == 1) {
|
if (NumOperands == 1) {
|
||||||
if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) {
|
if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) {
|
||||||
|
if (Name == "llvm.convert.to.fp16") {
|
||||||
|
APFloat Val(Op->getValueAPF());
|
||||||
|
|
||||||
|
bool lost = false;
|
||||||
|
Val.convert(APFloat::IEEEhalf, APFloat::rmNearestTiesToEven, &lost);
|
||||||
|
|
||||||
|
return ConstantInt::get(F->getContext(), Val.bitcastToAPInt());
|
||||||
|
}
|
||||||
|
|
||||||
if (!Ty->isFloatTy() && !Ty->isDoubleTy())
|
if (!Ty->isFloatTy() && !Ty->isDoubleTy())
|
||||||
return 0;
|
return 0;
|
||||||
/// Currently APFloat versions of these functions do not exist, so we use
|
/// Currently APFloat versions of these functions do not exist, so we use
|
||||||
@@ -1158,6 +1169,20 @@ llvm::ConstantFoldCall(Function *F,
|
|||||||
return ConstantInt::get(Ty, Op->getValue().countTrailingZeros());
|
return ConstantInt::get(Ty, Op->getValue().countTrailingZeros());
|
||||||
else if (Name.startswith("llvm.ctlz"))
|
else if (Name.startswith("llvm.ctlz"))
|
||||||
return ConstantInt::get(Ty, Op->getValue().countLeadingZeros());
|
return ConstantInt::get(Ty, Op->getValue().countLeadingZeros());
|
||||||
|
else if (Name == "llvm.convert.from.fp16") {
|
||||||
|
APFloat Val(Op->getValue());
|
||||||
|
|
||||||
|
bool lost = false;
|
||||||
|
APFloat::opStatus status =
|
||||||
|
Val.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &lost);
|
||||||
|
|
||||||
|
// Conversion is always precise.
|
||||||
|
status = status;
|
||||||
|
assert(status == APFloat::opOK && !lost &&
|
||||||
|
"Precision lost during fp16 constfolding");
|
||||||
|
|
||||||
|
return ConstantFP::get(F->getContext(), Val);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user