[llvm-branch-commits] [mlir] [mlir][OpenMP] Fix update of linear iteration variables (PR #183800)

Tom Eccles via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue May 26 07:57:13 PDT 2026


================
@@ -189,6 +190,26 @@ class LinearClauseProcessor {
     }
   }
 
+  // Find linear iteration variable and save it for later updates
+  void initLinearIV(omp::SimdOp simdOp) {
+    auto loopOp = cast<omp::LoopNestOp>(simdOp.getWrappedLoop());
+    // NOTE iteration variables can only be linear in non-nested loops.
+    if (loopOp.getIVs().size() != 1)
+      return;
+    // The linear IV is the loop IV's store address.
+    BlockArgument arg = loopOp.getIVs().front();
+    for (const Operation *user : arg.getUsers()) {
+      if (auto storeOp = dyn_cast<LLVM::StoreOp>(user)) {
+        for (Value linearVar : simdOp.getLinearVars()) {
----------------
tblah wrote:

This fails if the linear loop iteration variable is not stored directly to an address listed in simdOp.getLinearVars(). This can happen in cases like `linear(%i ...) private(... %i -> %arg0 ...)` because the loopIV is stored to `%arg0`.

If I understand correctly, this case is avoided by the earlier flang patches, but I think we do at least need a translation failure here in MLIR for this case so that any future frontends using this understand the limitation. Ideally, this should be checked in the OpenMP dialect verifier.

Note that this form is still used in `mlir/test/Target/LLVMIR/openmp-simd-ordered.mlir`.

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


More information about the llvm-branch-commits mailing list