[flang-commits] [flang] [flang][openmp] Fix incorrect reduction for array section in OpenMP DO SIMD (PR #192394)

via flang-commits flang-commits at lists.llvm.org
Thu Apr 16 08:33:44 PDT 2026


================
@@ -3643,6 +3601,22 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
       converter, loc, wsloopClauseOps, wsloopArgs);
   wsloopOp.setComposite(/*val=*/true);
 
+  // For composite DO SIMD, the simd reduction vars must reference the
+  // wsloop's reduction block args (thread-private copies) rather than the
+  // original variables. This ensures that
+  //   1) per-SIMD-lane reduction results are combined into the wsloop's
+  //   thread-local copies
+  //   2) wsloop thread-local copies are combined across
+  //   threads by the wsloop reduction.
+  auto wsloopBlockArgIface =
+      llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*wsloopOp);
+  for (unsigned i = 0; i < simdClauseOps.reductionVars.size() &&
+                       i < wsloopBlockArgIface.numReductionBlockArgs();
+       ++i) {
+    simdClauseOps.reductionVars[i] =
+        wsloopBlockArgIface.getReductionBlockArgs()[i];
+  }
----------------
SunilKuravinakop wrote:

Thanks for the quick feedback to you and @tblah. I will look into it.

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


More information about the flang-commits mailing list