[llvm] r278200 - [SimplifyLibCalls] Restore the old behaviour, emit a libcall.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 23:33:32 PDT 2016


Author: davide
Date: Wed Aug 10 01:33:32 2016
New Revision: 278200

URL: http://llvm.org/viewvc/llvm-project?rev=278200&view=rev
Log:
[SimplifyLibCalls] Restore the old behaviour, emit a libcall.

Hal pointed out that the semantic of our intrinsic and the libc
call are slightly different. Add a comment while I'm here to
explain why we can't emit an intrinsic. Thanks Hal!

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=278200&r1=278199&r2=278200&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Wed Aug 10 01:33:32 2016
@@ -1052,9 +1052,11 @@ Value *LibCallSimplifier::optimizePow(Ca
     if (CI->hasUnsafeAlgebra()) {
       IRBuilder<>::FastMathFlagGuard Guard(B);
       B.setFastMathFlags(CI->getFastMathFlags());
-      Value *Sqrt = Intrinsic::getDeclaration(CI->getModule(), Intrinsic::sqrt,
-                                              Op1->getType());
-      return B.CreateCall(Sqrt, Op1, "sqrt");
+
+      // Unlike other math intrinsics, sqrt has differerent semantics
+      // from the libc function. See LangRef for details.
+      return emitUnaryFloatFnCall(Op1, TLI->getName(LibFunc::sqrt), B,
+                                  Callee->getAttributes());
     }
 
     // Expand pow(x, 0.5) to (x == -infinity ? +infinity : fabs(sqrt(x))).

Modified: llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll?rev=278200&r1=278199&r2=278200&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll Wed Aug 10 01:33:32 2016
@@ -6,7 +6,7 @@ define double @pow_half(double %x) {
 }
 
 ; CHECK-LABEL: define double @pow_half(
-; CHECK-NEXT:  %sqrt = call fast double @llvm.sqrt.f64(double %x)
+; CHECK-NEXT:  %sqrt = call fast double @sqrt(double %x)
 ; CHECK-NEXT:  ret double %sqrt
 
 declare double @llvm.pow.f64(double, double)




More information about the llvm-commits mailing list