From: Matt Arsenault Date: Tue, 17 Jan 2017 00:30:31 +0000 (+0000) Subject: SimplifyLibCalls: Remove checks for fabs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bd79e8a808960df3e57a00c3d8bb0646ca76749;p=llvm SimplifyLibCalls: Remove checks for fabs Use the intrinsic instead of emitting the libcall which will be replaced by the intrinsic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292176 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index 945814e3a86..979aea2e1e1 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1094,9 +1094,7 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) { if (Op2C->isExactlyValue(0.5) && hasUnaryFloatFn(TLI, Op2->getType(), LibFunc::sqrt, LibFunc::sqrtf, - LibFunc::sqrtl) && - hasUnaryFloatFn(TLI, Op2->getType(), LibFunc::fabs, LibFunc::fabsf, - LibFunc::fabsl)) { + LibFunc::sqrtl)) { // In -ffast-math, pow(x, 0.5) -> sqrt(x). if (CI->hasUnsafeAlgebra()) { @@ -1116,8 +1114,12 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) { Value *Inf = ConstantFP::getInfinity(CI->getType()); Value *NegInf = ConstantFP::getInfinity(CI->getType(), true); Value *Sqrt = emitUnaryFloatFnCall(Op1, "sqrt", B, Callee->getAttributes()); - Value *FAbs = - emitUnaryFloatFnCall(Sqrt, "fabs", B, Callee->getAttributes()); + + Module *M = Callee->getParent(); + Function *FabsF = Intrinsic::getDeclaration(M, Intrinsic::fabs, + CI->getType()); + Value *FAbs = B.CreateCall(FabsF, Sqrt); + Value *FCmp = B.CreateFCmpOEQ(Op1, NegInf); Value *Sel = B.CreateSelect(FCmp, Inf, FAbs); return Sel; diff --git a/test/Transforms/InstCombine/win-math.ll b/test/Transforms/InstCombine/win-math.ll index 47e99607a25..42b315928b7 100644 --- a/test/Transforms/InstCombine/win-math.ll +++ b/test/Transforms/InstCombine/win-math.ll @@ -279,9 +279,12 @@ define float @float_powsqrt(float %x) nounwind readnone { ; WIN32-LABEL: @float_powsqrt( ; WIN32-NOT: float @sqrtf ; WIN32: float @powf + ; WIN64-LABEL: @float_powsqrt( -; WIN64-NOT: float @sqrtf -; WIN64: float @powf +; WIN64: float @sqrtf +; WIN64: float @llvm.fabs.f32( +; WIN64-NOT: float @powf + ; MINGW32-LABEL: @float_powsqrt( ; MINGW32: float @sqrtf ; MINGW32: float @llvm.fabs.f32