[flang-commits] [flang] [Flang] [OpenMP] Run `MarkDeclareTarget` pass again after `ConvertMathToFuncs` (PR #210049)

Soham Karandikar via flang-commits flang-commits at lists.llvm.org
Thu Jul 16 06:04:17 PDT 2026


https://github.com/skadewdl3 created https://github.com/llvm/llvm-project/pull/210049

Fixes #209123.

The power operation `math.ipowi` is converted to a function by `ConvertMathToFuncs`. When used in a target region, this pass runs well after `MarkDeclareTarget` which causes the newly created power function to not have the `omp.declare_target` attribute - thus causing lowering issues. Detailed investigation [here](https://github.com/llvm/llvm-project/issues/209123#issuecomment-4991765854).

Right now, I've just added a couple of lines to run `MarkDeclareTarget` again, after `ConvertMathToFuncs`. Since I'm quite new to this, I'd like some help on whether this is acceptable, or should the `MarkDeclareTarget` pass be moved to after `ConvertMathToFuncs`.

>From d72c000a48cf01c5ea9f4e837be6464d05d64ecd Mon Sep 17 00:00:00 2001
From: Soham Karandikar <sohamk10 at gmail.com>
Date: Thu, 16 Jul 2026 07:57:24 -0500
Subject: [PATCH] Run `MarkDeclareTarget` pass again after `ConvertMathToFuncs`

---
 flang/lib/Optimizer/Passes/Pipelines.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 879a224824119..7fe8bccc14d54 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -464,6 +464,11 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
   pm.addPass(fir::createEmitMIFGlobalCtors());
 
   if (config.EnableOpenMP && !config.EnableOpenMPSimd) {
+    // Since some math operations may be converted to function calls by the
+    // ConvertMathToFuncs pass, we need to mark them with the omp.declare_target
+    // attribute if they're called from a target region.
+    pm.addPass(mlir::omp::createMarkDeclareTargetPass());
+
     // Remove all non target-related operations from host functions still
     // remaining at this point, if compiling for an OpenMP target device. This
     // is required before translating 'omp' dialect operations to LLVM IR.



More information about the flang-commits mailing list