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))).
}
; 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)