Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions flang/lib/Optimizer/Builder/IntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,11 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::StringRef mathLibFuncName = mathOp.runtimeFunc;
if (!mathLibFuncName.empty()) {
// If we enabled MLIR complex or can use approximate operations, we should
// NOT use libm.
if (!forceMlirComplex && !canUseApprox) {
// NOT use libm. Avoid libm when targeting AMDGPU as those symbols are not
// available on the device and we rely on MLIR complex operations to
// later map to OCML calls.
bool isAMDGPU = fir::getTargetTriple(builder.getModule()).isAMDGCN();
if (!forceMlirComplex && !canUseApprox && !isAMDGPU) {
result = genLibCall(builder, loc, mathOp, mathLibFuncType, args);
LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n");
return result;
Expand Down
21 changes: 21 additions & 0 deletions flang/test/Lower/amdgcn-complex.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
! REQUIRES: amdgpu-registered-target
! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s

subroutine cabsf_test(a, b)
complex :: a
real :: b
b = abs(a)
end subroutine

! CHECK-LABEL: func @_QPcabsf_test(
! CHECK: complex.abs
! CHECK-NOT: fir.call @cabsf

subroutine cexpf_test(a, b)
complex :: a, b
b = exp(a)
end subroutine

! CHECK-LABEL: func @_QPcexpf_test(
! CHECK: complex.exp
! CHECK-NOT: fir.call @cexpf
Loading