Skip to content

Commit b948b4d

Browse files
committed
SimplifyLibCalls: Remove checks for fabs
Use the intrinsic instead of emitting the libcall which will be replaced by the intrinsic. llvm-svn: 292176
1 parent 0d7d9c2 commit b948b4d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,7 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) {
10941094

10951095
if (Op2C->isExactlyValue(0.5) &&
10961096
hasUnaryFloatFn(TLI, Op2->getType(), LibFunc::sqrt, LibFunc::sqrtf,
1097-
LibFunc::sqrtl) &&
1098-
hasUnaryFloatFn(TLI, Op2->getType(), LibFunc::fabs, LibFunc::fabsf,
1099-
LibFunc::fabsl)) {
1097+
LibFunc::sqrtl)) {
11001098

11011099
// In -ffast-math, pow(x, 0.5) -> sqrt(x).
11021100
if (CI->hasUnsafeAlgebra()) {
@@ -1116,8 +1114,12 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) {
11161114
Value *Inf = ConstantFP::getInfinity(CI->getType());
11171115
Value *NegInf = ConstantFP::getInfinity(CI->getType(), true);
11181116
Value *Sqrt = emitUnaryFloatFnCall(Op1, "sqrt", B, Callee->getAttributes());
1119-
Value *FAbs =
1120-
emitUnaryFloatFnCall(Sqrt, "fabs", B, Callee->getAttributes());
1117+
1118+
Module *M = Callee->getParent();
1119+
Function *FabsF = Intrinsic::getDeclaration(M, Intrinsic::fabs,
1120+
CI->getType());
1121+
Value *FAbs = B.CreateCall(FabsF, Sqrt);
1122+
11211123
Value *FCmp = B.CreateFCmpOEQ(Op1, NegInf);
11221124
Value *Sel = B.CreateSelect(FCmp, Inf, FAbs);
11231125
return Sel;

llvm/test/Transforms/InstCombine/win-math.ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,12 @@ define float @float_powsqrt(float %x) nounwind readnone {
279279
; WIN32-LABEL: @float_powsqrt(
280280
; WIN32-NOT: float @sqrtf
281281
; WIN32: float @powf
282+
282283
; WIN64-LABEL: @float_powsqrt(
283-
; WIN64-NOT: float @sqrtf
284-
; WIN64: float @powf
284+
; WIN64: float @sqrtf
285+
; WIN64: float @llvm.fabs.f32(
286+
; WIN64-NOT: float @powf
287+
285288
; MINGW32-LABEL: @float_powsqrt(
286289
; MINGW32: float @sqrtf
287290
; MINGW32: float @llvm.fabs.f32

0 commit comments

Comments
 (0)