[PATCH] D28453: SimplifyLibCalls: Remove checks for fabs

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 7 20:22:13 PST 2017


arsenm created this revision.
arsenm added a reviewer: efriedma.
arsenm added a subscriber: llvm-commits.
Herald added a subscriber: wdng.

Use the intrinsic instead of emitting the libcall which
will be replaced by the intrinsic.

There are some additional places using this like ConstantFolding that may want to stay


https://reviews.llvm.org/D28453

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


Index: test/Transforms/InstCombine/win-math.ll
===================================================================
--- test/Transforms/InstCombine/win-math.ll
+++ test/Transforms/InstCombine/win-math.ll
@@ -279,9 +279,12 @@
 ; 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
Index: lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1076,9 +1076,7 @@
 
   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()) {
@@ -1098,8 +1096,12 @@
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28453.83546.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170108/c3cd95c7/attachment.bin>


More information about the llvm-commits mailing list