]> granicus.if.org Git - llvm/commitdiff
SimplifyLibCalls: Remove checks for fabs
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 17 Jan 2017 00:30:31 +0000 (00:30 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 17 Jan 2017 00:30:31 +0000 (00:30 +0000)
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

lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/win-math.ll

index 945814e3a8616a4fe3bd8d710feff556a5e61ba9..979aea2e1e1143b5ebfa9c98a414f5420e602c26 100644 (file)
@@ -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;
index 47e99607a25e43b478fbf352ce819329b3128c94..42b315928b7bb3902adaf9ad997a266e929fd735 100644 (file)
@@ -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