[flang-commits] [flang] [Flang] Force lowering to Complex for AMDGPU (PR #144927)

Akash Banerjee via flang-commits flang-commits at lists.llvm.org
Thu Jun 19 09:51:41 PDT 2025


https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/144927

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.

PRs #144924 & #144926 add additional related support.

>From 8733392d6c8d0db6b3b03c44bce8adfac45fa364 Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Thu, 19 Jun 2025 17:44:03 +0100
Subject: [PATCH] [Flang] Force lowering to Complex for AMDGPU

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.
---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 178b6770d6b53..2ca7f2784aab3 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -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;



More information about the flang-commits mailing list