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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Kareem Ergawy (ergawy)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/175172.diff


2 Files Affected:

- (modified) flang/lib/Lower/Support/ReductionProcessor.cpp (-20) 
- (modified) flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp (+24) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list