[llvm] [ConstantFold] Fix result type when folding powi.f16 (PR #98681)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 12:57:55 PDT 2024
================
@@ -2760,11 +2760,13 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy())
return nullptr;
- if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy())
- return ConstantFP::get(
- Ty->getContext(),
- APFloat((float)std::pow((float)Op1V.convertToDouble(),
- (int)Op2C->getZExtValue())));
+ if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy()) {
+ APFloat Res((float)std::pow((float)Op1V.convertToDouble(),
+ (int)Op2C->getZExtValue()));
+ bool unused;
+ Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &unused);
+ return ConstantFP::get(Ty->getContext(), Res);
----------------
nikic wrote:
Can we combine/simplify all three branches to this?
```
return ConstantFP::get(Ty, std::pow(Op1V.convertToDouble(),
(int)Op2C->getZExtValue()));
```
There is a ConstantFP::get(Type, double) overload.
https://github.com/llvm/llvm-project/pull/98681
More information about the llvm-commits
mailing list