diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-07-15 14:59:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 14:59:16 +0800 |
commit | caa0e42ceb6e671d68b8b8e1d04f136696a4228b (patch) | |
tree | ce3cc95448924ab6d0b63ff32cc7574ac849660c | |
parent | 5555a9e657939dafb569a825fecd1d0f4202b21d (diff) | |
download | llvm-caa0e42ceb6e671d68b8b8e1d04f136696a4228b.zip llvm-caa0e42ceb6e671d68b8b8e1d04f136696a4228b.tar.gz llvm-caa0e42ceb6e671d68b8b8e1d04f136696a4228b.tar.bz2 |
Fix assertion failure in PR98681 (#98860)
See https://en.cppreference.com/w/cpp/numeric/math/pow:
```
C++98 added overloads where exp has type int on top of C [pow()](https://en.cppreference.com/w/c/numeric/math/pow), and the return type of std::pow(float, int) was float. However, the additional overloads introduced in C++11 specify that std::pow(float, int) should return double. [LWG issue 550](https://cplusplus.github.io/LWG/issue550) was raised to target this conflict, and the resolution is to removed the extra int exp overloads.
```
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Transforms/EarlyCSE/math-2.ll | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 6c52091..df75745 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2759,7 +2759,7 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty, switch (Ty->getTypeID()) { case Type::HalfTyID: case Type::FloatTyID: { - APFloat Res(std::pow(Op1V.convertToFloat(), Exp)); + APFloat Res(static_cast<float>(std::pow(Op1V.convertToFloat(), Exp))); if (Ty->isHalfTy()) { bool Unused; Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, diff --git a/llvm/test/Transforms/EarlyCSE/math-2.ll b/llvm/test/Transforms/EarlyCSE/math-2.ll index 60a2f19..0d55165 100644 --- a/llvm/test/Transforms/EarlyCSE/math-2.ll +++ b/llvm/test/Transforms/EarlyCSE/math-2.ll @@ -108,4 +108,12 @@ define half @pr98665() { ret half %x } +define float @powi_f32() { +; CHECK-LABEL: @powi_f32( +; CHECK-NEXT: ret float 0.000000e+00 +; + %y = call float @llvm.powi.f32.i32(float 0.0, i32 10) + ret float %y +} + attributes #0 = { nofree nounwind willreturn } |