diff options
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 8 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/pow-sqrt.ll | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index a958eeeae88..c10a1ff6dab 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1052,9 +1052,11 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) { 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))). diff --git a/llvm/test/Transforms/InstCombine/pow-sqrt.ll b/llvm/test/Transforms/InstCombine/pow-sqrt.ll index 27d804dd5fc..1e6166c5f11 100644 --- a/llvm/test/Transforms/InstCombine/pow-sqrt.ll +++ b/llvm/test/Transforms/InstCombine/pow-sqrt.ll @@ -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) |

