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

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Tue Jun 23 06:55:10 PDT 2026


================
@@ -436,18 +436,28 @@ static void bindEntryBlockArgs(lower::AbstractConverter &converter,
               .first);
   };
 
-  // Process in clause name alphabetical order to match block arguments order.
   // Do not bind host_eval variables because they cannot be used inside of the
   // corresponding region, except for very specific cases handled separately.
+  //
+  // For `omp.task` / `omp.taskloop`, `in_reduction` list items have their own
+  // entry block argument and are bound here like other private-like variables.
+  //
+  // `in_reduction` list items on `omp.target` are not given their own entry
+  // block argument (`args.inReduction` is left empty for target), so the
+  // in_reduction bind below is a no-op there. Instead they are implicitly
+  // mapped, so in-body references resolve to the `map_entries` block argument
+  // bound here; the host side uses the `in_reduction` clause metadata to
+  // redirect that mapped value to the per-task reduction-private storage during
+  // translation.
   bindMapLike(args.hasDeviceAddr.objects, op.getHasDeviceAddrBlockArgs());
-  bindPrivateLike(args.inReduction.objects, args.inReduction.vars,
-                  op.getInReductionBlockArgs());
   bindMapLike(args.map.objects, op.getMapBlockArgs());
   bindPrivateLike(args.priv.objects, args.priv.vars, op.getPrivateBlockArgs());
   bindPrivateLike(args.reduction.objects, args.reduction.vars,
                   op.getReductionBlockArgs());
   bindPrivateLike(args.taskReduction.objects, args.taskReduction.vars,
                   op.getTaskReductionBlockArgs());
+  bindPrivateLike(args.inReduction.objects, args.inReduction.vars,
----------------
skatrak wrote:

Is moving this still necessary after removing the `map`+`in_reduction` interaction? If so, there should be a comment to state that binding `in_reduction` must be done after whichever other entry block argument-generating clauses it conflicts with.

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


More information about the flang-commits mailing list