[flang-commits] [flang] [llvm] [mlir] [flang][OpenMP] Lower target in_reduction for host fallback (PR #199967)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Jul 13 05:20:21 PDT 2026


================
@@ -2655,6 +2739,35 @@ LogicalResult TargetOp::verify() {
   if (failed(verifyPrivateVarList(*this)))
     return failure();
 
+  if (failed(verifyReductionVarList(*this, getInReductionSyms(),
+                                    getInReductionVars(),
+                                    getInReductionByref())))
+    return failure();
+
+  // An `in_reduction` operand on `omp.target` has no dedicated entry block
+  // argument; inside the region it is accessed through the block argument of a
+  // matching `map_entries` entry, and the host fallback rewrites that map
+  // argument to the reduction-private storage. Require every `in_reduction`
+  // operand to be captured by at least one `map_entries` entry whose
+  // `MapInfoOp` var_ptr is the same value, or another result of the same
+  // defining op. Flang emits e.g. `hlfir.declare`#0 for the `in_reduction`
+  // operand and `hlfir.declare`#1 for the map var_ptr, so exact value identity
+  // is not required; block arguments (no defining op) must match exactly.
+  for (Value inReductionVar : getInReductionVars()) {
+    bool captured = false;
+    for (Value mapVar : getMapVars()) {
+      auto mapInfo = mapVar.getDefiningOp<MapInfoOp>();
+      if (mapInfo &&
+          targetInReductionCapturedBy(inReductionVar, mapInfo.getVarPtr())) {
+        captured = true;
+        break;
+      }
----------------
skatrak wrote:

```suggestion
      auto mapInfo = mapVar.getDefiningOp<MapInfoOp>();
      if (targetInReductionCapturedBy(inReductionVar, mapInfo.getVarPtr())) {
        captured = true;
        break;
      }
```

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


More information about the flang-commits mailing list