Skip to content

Commit db4d6ef

Browse files
committed
AMDGPU: Directly emit fabs intrinsic instead of new libcall
1 parent 2dea832 commit db4d6ef

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,11 +1036,7 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
10361036

10371037
Value *nval;
10381038
if (needabs) {
1039-
FunctionCallee AbsExpr =
1040-
getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_FABS, FInfo));
1041-
if (!AbsExpr)
1042-
return false;
1043-
nval = CreateCallEx(B, AbsExpr, opr0, "__fabs");
1039+
nval = B.CreateUnaryIntrinsic(Intrinsic::fabs, opr0, nullptr, "__fabs");
10441040
} else {
10451041
nval = cnval ? cnval : opr0;
10461042
}

llvm/test/CodeGen/AMDGPU/simplify-libcalls.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ declare float @_Z4pownfi(float, i32)
347347

348348
; GCN-LABEL: {{^}}define amdgpu_kernel void @test_pow
349349
; GCN-POSTLINK: call fast float @_Z3powff(float %tmp, float 1.013000e+03)
350-
; GCN-PRELINK: %__fabs = tail call fast float @_Z4fabsf(float %tmp)
350+
; GCN-PRELINK: %__fabs = tail call fast float @llvm.fabs.f32(float %tmp)
351351
; GCN-PRELINK: %__log2 = tail call fast float @_Z4log2f(float %__fabs)
352352
; GCN-PRELINK: %__ylogx = fmul fast float %__log2, 1.013000e+03
353353
; GCN-PRELINK: %__exp2 = tail call fast float @_Z4exp2f(float %__ylogx)
@@ -387,7 +387,7 @@ entry:
387387
; GCN-LABEL: {{^}}define amdgpu_kernel void @test_pown
388388
; GCN-POSTLINK: call fast float @_Z4pownfi(float %tmp, i32 %conv)
389389
; GCN-PRELINK: %conv = fptosi float %tmp1 to i32
390-
; GCN-PRELINK: %__fabs = tail call fast float @_Z4fabsf(float %tmp)
390+
; GCN-PRELINK: %__fabs = tail call fast float @llvm.fabs.f32(float %tmp)
391391
; GCN-PRELINK: %__log2 = tail call fast float @_Z4log2f(float %__fabs)
392392
; GCN-PRELINK: %pownI2F = sitofp i32 %conv to float
393393
; GCN-PRELINK: %__ylogx = fmul fast float %__log2, %pownI2F
@@ -784,8 +784,7 @@ entry:
784784
ret void
785785
}
786786

787-
; GCN-PRELINK: declare float @_Z4fabsf(float) local_unnamed_addr #[[$NOUNWIND_READONLY:[0-9]+]]
788-
; GCN-PRELINK: declare float @_Z4cbrtf(float) local_unnamed_addr #[[$NOUNWIND_READONLY]]
787+
; GCN-PRELINK: declare float @_Z4cbrtf(float) local_unnamed_addr #[[$NOUNWIND_READONLY:[0-9]+]]
789788
; GCN-PRELINK: declare float @_Z11native_sqrtf(float) local_unnamed_addr #[[$NOUNWIND_READONLY]]
790789

791790
; GCN-PRELINK: attributes #[[$NOUNWIND]] = { nounwind }

0 commit comments

Comments
 (0)