diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-07-15 13:00:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 13:00:25 +0800 |
commit | 34bfed63313d1340378fc1be931253333db8c36c (patch) | |
tree | f1643d8b0c79977b1c61c06a61b3234ed37697f3 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 662c6fc74c1ae7fdefd27524dfaeb7f3e9a1f553 (diff) | |
download | llvm-34bfed63313d1340378fc1be931253333db8c36c.zip llvm-34bfed63313d1340378fc1be931253333db8c36c.tar.gz llvm-34bfed63313d1340378fc1be931253333db8c36c.tar.bz2 |
[ConstantFold] Fix result type when folding powi.f16 (#98681)
Fixes #98665.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 962880f..6c52091 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2754,27 +2754,28 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty, ((Mask & fcPosInf) && Op1V.isPosInfinity()); return ConstantInt::get(Ty, Result); } + case Intrinsic::powi: { + int Exp = static_cast<int>(Op2C->getSExtValue()); + switch (Ty->getTypeID()) { + case Type::HalfTyID: + case Type::FloatTyID: { + APFloat Res(std::pow(Op1V.convertToFloat(), Exp)); + if (Ty->isHalfTy()) { + bool Unused; + Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, + &Unused); + } + return ConstantFP::get(Ty->getContext(), Res); + } + case Type::DoubleTyID: + return ConstantFP::get(Ty, std::pow(Op1V.convertToDouble(), Exp)); + default: + return nullptr; + } + } default: break; } - - 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->isFloatTy()) - return ConstantFP::get( - Ty->getContext(), - APFloat((float)std::pow((float)Op1V.convertToDouble(), - (int)Op2C->getZExtValue()))); - if (IntrinsicID == Intrinsic::powi && Ty->isDoubleTy()) - return ConstantFP::get( - Ty->getContext(), - APFloat((double)std::pow(Op1V.convertToDouble(), - (int)Op2C->getZExtValue()))); } return nullptr; } |