[Mlir-commits] [llvm] [mlir] [OpenMP] Fix missing implicit barriers in device worksharing loops (PR #227735)

Sergio Afonso llvmlistbot at llvm.org
Thu Oct 1 03:20:16 PDT 2026


================
@@ -6721,6 +6720,17 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoopTarget(
                                 LoopType, NoLoop);
   };
   addOutlineInfo(std::move(OI));
+
+  // Keep the barrier outside the outlined loop body so that every thread
+  // encounters it, including threads that execute no iterations.
+  if (NeedsBarrier) {
+    Builder.SetInsertPoint(CLI->getExit()->getTerminator());
+    InsertPointOrErrorTy BarrierIP =
+        createBarrier(LocationDescription(Builder.saveIP(), DL), OMPD_for,
----------------
skatrak wrote:

Nit: This always sets the directive kind for the barrier to `for`, regardless of the `LoopType`. This function is reached when translating `omp.wsloop`, but also `omp.distribute` and composite `omp.distribute` + `omp.wsloop`.

Looking at the `createBarrier` implementation and the fact that `distribute` never creates a barrier, this seems to be correct. However, I'd suggest adding a small comment to describe this, as it's not entirely evident without all that other context.

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


More information about the Mlir-commits mailing list