Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1711,13 +1711,6 @@ // Propagate the math semantics from the call to any created instructions. IRBuilderBase::FastMathFlagGuard Guard(B); B.setFastMathFlags(Pow->getFastMathFlags()); - - // Shrink pow() to powf() if the arguments are single precision, - // unless the result is expected to be double precision. - if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) && - hasFloatVersion(Name)) - Shrunk = optimizeBinaryDoubleFP(Pow, B, true); - // Evaluate special cases related to the base. // pow(1.0, x) -> 1.0 @@ -1818,6 +1811,12 @@ return createPowWithIntegerExponent(Base, ExpoI, M, B); } + // Shrink pow() to powf() if the arguments are single precision, + // unless the result is expected to be double precision. + if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) && + hasFloatVersion(Name)) + Shrunk = optimizeBinaryDoubleFP(Pow, B, true); + return Shrunk; } Index: llvm/test/Transforms/InstCombine/pow-4.ll =================================================================== --- llvm/test/Transforms/InstCombine/pow-4.ll +++ llvm/test/Transforms/InstCombine/pow-4.ll @@ -1,7 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -instcombine -S < %s | FileCheck %s --check-prefixes=CHECK,SQRT ; RUN: opt -instcombine -S < %s -disable-builtin sqrt | FileCheck %s --check-prefixes=CHECK,NOSQRT - declare double @llvm.pow.f64(double, double) declare float @llvm.pow.f32(float, float) declare <2 x double> @llvm.pow.v2f64(<2 x double>, <2 x double>) @@ -235,12 +234,10 @@ } ; (float)pow((double)(float)x, 0.5) -; FIXME: One call to `sqrtf` would suffice (PR47613). define float @shrink_pow_libcall_half(float %x) { ; SQRT-LABEL: @shrink_pow_libcall_half( -; SQRT-NEXT: [[SQRTF:%.*]] = call fast float @sqrtf(float [[X:%.*]]) -; SQRT-NEXT: [[SQRTF1:%.*]] = call fast float @sqrtf(float [[X]]) -; SQRT-NEXT: ret float [[SQRTF1]] +; SQRT-NEXT: [[SQRTF:%.*]] = call fast float @sqrtf(float [[X]]) +; SQRT-NEXT: ret float [[SQRTF]] ; ; NOSQRT-LABEL: @shrink_pow_libcall_half( ; NOSQRT-NEXT: [[SQRTF:%.*]] = call fast float @sqrtf(float [[X:%.*]])