Skip to content

Commit 1742966

Browse files
authored
[Flang] Force lowering to Complex for AMDGPU (#144927)
1 parent c71b92d commit 1742966

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,11 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc,
12311231
llvm::StringRef mathLibFuncName = mathOp.runtimeFunc;
12321232
if (!mathLibFuncName.empty()) {
12331233
// If we enabled MLIR complex or can use approximate operations, we should
1234-
// NOT use libm.
1235-
if (!forceMlirComplex && !canUseApprox) {
1234+
// NOT use libm. Avoid libm when targeting AMDGPU as those symbols are not
1235+
// available on the device and we rely on MLIR complex operations to
1236+
// later map to OCML calls.
1237+
bool isAMDGPU = fir::getTargetTriple(builder.getModule()).isAMDGCN();
1238+
if (!forceMlirComplex && !canUseApprox && !isAMDGPU) {
12361239
result = genLibCall(builder, loc, mathOp, mathLibFuncType, args);
12371240
LLVM_DEBUG(result.dump(); llvm::dbgs() << "\n");
12381241
return result;

flang/test/Lower/amdgcn-complex.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! REQUIRES: amdgpu-registered-target
2+
! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s
3+
4+
subroutine cabsf_test(a, b)
5+
complex :: a
6+
real :: b
7+
b = abs(a)
8+
end subroutine
9+
10+
! CHECK-LABEL: func @_QPcabsf_test(
11+
! CHECK: complex.abs
12+
! CHECK-NOT: fir.call @cabsf
13+
14+
subroutine cexpf_test(a, b)
15+
complex :: a, b
16+
b = exp(a)
17+
end subroutine
18+
19+
! CHECK-LABEL: func @_QPcexpf_test(
20+
! CHECK: complex.exp
21+
! CHECK-NOT: fir.call @cexpf

0 commit comments

Comments
 (0)