diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 3b4e60315662..74468e8dd72c 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1517,14 +1517,12 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) { namespace { Constant *GetConstantFoldFPValue(double V, Type *Ty) { - if (Ty->isHalfTy()) { + if (Ty->isHalfTy() || Ty->isFloatTy()) { APFloat APF(V); bool unused; - APF.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &unused); + APF.convert(Ty->getFltSemantics(), APFloat::rmNearestTiesToEven, &unused); return ConstantFP::get(Ty->getContext(), APF); } - if (Ty->isFloatTy()) - return ConstantFP::get(Ty->getContext(), APFloat((float)V)); if (Ty->isDoubleTy()) return ConstantFP::get(Ty->getContext(), APFloat(V)); llvm_unreachable("Can only constant fold half/float/double"); diff --git a/llvm/test/Transforms/ConstProp/calls.ll b/llvm/test/Transforms/ConstProp/calls.ll index 161637cc92b8..12ee1cb11393 100644 --- a/llvm/test/Transforms/ConstProp/calls.ll +++ b/llvm/test/Transforms/ConstProp/calls.ll @@ -193,4 +193,14 @@ entry: ret double %0 } +define float @test_intrinsic_pow_f32_overflow() nounwind uwtable ssp { +entry: +; CHECK-LABEL: @test_intrinsic_pow_f32_overflow( +; CHECK-NOT: call +; CHECK: ret float 0x7FF0000000000000 + %0 = call float @llvm.pow.f32(float 40.0, float 50.0) + ret float %0 +} + declare double @llvm.pow.f64(double, double) nounwind readonly +declare float @llvm.pow.f32(float, float) nounwind readonly