Skip to content

Commit caa0e42

Browse files
authored
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. ```
1 parent 5555a9e commit caa0e42

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,7 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
27592759
switch (Ty->getTypeID()) {
27602760
case Type::HalfTyID:
27612761
case Type::FloatTyID: {
2762-
APFloat Res(std::pow(Op1V.convertToFloat(), Exp));
2762+
APFloat Res(static_cast<float>(std::pow(Op1V.convertToFloat(), Exp)));
27632763
if (Ty->isHalfTy()) {
27642764
bool Unused;
27652765
Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven,

llvm/test/Transforms/EarlyCSE/math-2.ll

+8
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,12 @@ define half @pr98665() {
108108
ret half %x
109109
}
110110

111+
define float @powi_f32() {
112+
; CHECK-LABEL: @powi_f32(
113+
; CHECK-NEXT: ret float 0.000000e+00
114+
;
115+
%y = call float @llvm.powi.f32.i32(float 0.0, i32 10)
116+
ret float %y
117+
}
118+
111119
attributes #0 = { nofree nounwind willreturn }

0 commit comments

Comments
 (0)