Skip to content

Commit

Permalink
Fix assertion failure in PR98681 (#98860)
Browse files Browse the repository at this point in the history
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.
```
  • Loading branch information
dtcxzyw authored Jul 15, 2024
1 parent 5555a9e commit caa0e42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/Transforms/EarlyCSE/math-2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit caa0e42

Please sign in to comment.