[flang-commits] [flang] [OpenMP][flang] Move `todo` for checking reduction support status on the GPU (PR #175172)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Fri Jan 9 06:10:14 PST 2026


https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/175172

Moves a `todo` to check for the current level of support for by-ref reductions to the `FunctionFiltering` pass. This guarantees that the check does not trigger when the same module is compiled twice: on the CPU and on the GPU.

>From 5deefd0a44a11d708c7e3e1e31c41974f7b98594 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Fri, 9 Jan 2026 08:07:19 -0600
Subject: [PATCH] [OpenMP][flang] Move `todo` for checking reduction support
 status on the GPU

Moves a `todo` to check for the current level of support for by-ref
reductions to the `FunctionFiltering` pass. This guarantees that the
check does not trigger when the same module is compiled twice: on the
CPU and on the GPU.
---
 .../lib/Lower/Support/ReductionProcessor.cpp  | 20 ----------------
 .../Optimizer/OpenMP/FunctionFiltering.cpp    | 24 +++++++++++++++++++
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/flang/lib/Lower/Support/ReductionProcessor.cpp b/flang/lib/Lower/Support/ReductionProcessor.cpp
index db8ad909b1d2f..0e01268dd74ff 100644
--- a/flang/lib/Lower/Support/ReductionProcessor.cpp
+++ b/flang/lib/Lower/Support/ReductionProcessor.cpp
@@ -598,26 +598,6 @@ DeclareRedType ReductionProcessor::createDeclareReductionHelper(
   genCombinerCB(builder, loc, type, op1, op2, isByRef);
 
   if (isByRef && fir::isa_box_type(valTy)) {
-    bool isBoxReductionSupported = [&]() {
-      auto offloadMod = llvm::dyn_cast<mlir::omp::OffloadModuleInterface>(
-          *builder.getModule());
-
-      // This check tests the implementation status on the GPU. Box reductions
-      // are fully supported on the CPU.
-      if (!offloadMod.getIsGPU())
-        return true;
-
-      auto seqTy = mlir::dyn_cast<fir::SequenceType>(boxedTy);
-
-      // Dynamically-shaped arrays are not supported yet on the GPU.
-      return !seqTy || !fir::sequenceWithNonConstantShape(seqTy);
-    }();
-
-    if (!isBoxReductionSupported) {
-      TODO(loc, "Reduction of dynamically-shaped arrays are not supported yet "
-                "on the GPU.");
-    }
-
     mlir::Region &dataPtrPtrRegion = decl.getDataPtrPtrRegion();
     mlir::Block &dataAddrBlock = *builder.createBlock(
         &dataPtrPtrRegion, dataPtrPtrRegion.end(), {type}, {loc});
diff --git a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp b/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
index 3031bb5da6919..d0bd09e1d1e84 100644
--- a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
+++ b/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIROpsSupport.h"
 #include "flang/Optimizer/OpenMP/Passes.h"
@@ -101,6 +102,29 @@ class FunctionFilteringPass
       }
       return WalkResult::advance();
     });
+
+    if (op.getIsGPU())
+      op->walk<WalkOrder::PreOrder>([&](omp::DeclareReductionOp redOp) {
+        if (redOp.symbolKnownUseEmpty(op))
+          return WalkResult::advance();
+
+        if (!redOp.getByrefElementType())
+          return WalkResult::advance();
+
+        auto seqTy =
+            mlir::dyn_cast<fir::SequenceType>(*redOp.getByrefElementType());
+
+        bool isByRefReductionSupported =
+            !seqTy || !fir::sequenceWithNonConstantShape(seqTy);
+
+        if (!isByRefReductionSupported) {
+          TODO(redOp.getLoc(),
+               "Reduction of dynamically-shaped arrays are not supported yet "
+               "on the GPU.");
+        }
+
+        return WalkResult::advance();
+      });
   }
 };
 } // namespace



More information about the flang-commits mailing list