[Mlir-commits] [mlir] [mlir][scf] Skip ops having results with warning in forall-to-for pass (PR #175926)

Prathamesh Tagore llvmlistbot at llvm.org
Wed Jan 14 22:56:03 PST 2026


https://github.com/meshtag updated https://github.com/llvm/llvm-project/pull/175926

>From aaab041020c986345631d5e8bf0871957e93243e Mon Sep 17 00:00:00 2001
From: Prathamesh Tagore <prathameshtagore at gmail.com>
Date: Wed, 14 Jan 2026 16:54:40 +0530
Subject: [PATCH] [mlir][scf] Skip ops having results with warning in
 forall-to-for pass

Avoid converting scf.forall ops that have results in forall-to-for pass.
Emit a warning instead of failing the pass, so mlir-opt can still produce
output on mixed IR.
---
 .../Dialect/SCF/Transforms/ForallToFor.cpp    |  6 +++++
 mlir/test/Dialect/SCF/forall-to-for.mlir      | 24 +++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/mlir/lib/Dialect/SCF/Transforms/ForallToFor.cpp b/mlir/lib/Dialect/SCF/Transforms/ForallToFor.cpp
index 00bef707fadd3..20a64a3d2b4d7 100644
--- a/mlir/lib/Dialect/SCF/Transforms/ForallToFor.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/ForallToFor.cpp
@@ -30,6 +30,12 @@ mlir::scf::forallToForLoop(RewriterBase &rewriter, scf::ForallOp forallOp,
   OpBuilder::InsertionGuard guard(rewriter);
   rewriter.setInsertionPoint(forallOp);
 
+  if (!forallOp.getOutputs().empty()) {
+    forallOp.emitWarning()
+        << "skipping scf.forall with outputs, currently not supported";
+    return success();
+  }
+
   Location loc = forallOp.getLoc();
   SmallVector<Value> lbs = forallOp.getLowerBound(rewriter);
   SmallVector<Value> ubs = forallOp.getUpperBound(rewriter);
diff --git a/mlir/test/Dialect/SCF/forall-to-for.mlir b/mlir/test/Dialect/SCF/forall-to-for.mlir
index e7d183fb9d2b5..d917cd1d8d2d4 100644
--- a/mlir/test/Dialect/SCF/forall-to-for.mlir
+++ b/mlir/test/Dialect/SCF/forall-to-for.mlir
@@ -55,3 +55,27 @@ func.func @nested(%ub1: index, %ub2: index, %ub3: index, %ub4: index) {
   }
   return
 }
+
+// -----
+
+// The pass should bail out cleanly and not crash here. `scf.forall` with outputs
+// is not supported, but we should still handle the `forall` op with no results
+// present in the same function.
+
+func.func private @callee(%i: index)
+
+// CHECK-LABEL: @shared_outs
+func.func @shared_outs(%arg0: tensor<1xf32>, %ub: index) -> tensor<1xf32> {
+  // CHECK: %{{.*}} = scf.forall
+  %0 = scf.forall (%i) in (1) shared_outs(%out = %arg0) -> (tensor<1xf32>) {
+    scf.forall.in_parallel {
+      tensor.parallel_insert_slice %out into %out[%i] [1] [1] : tensor<1xf32> into tensor<1xf32>
+    }
+  }
+
+  // CHECK: scf.for
+  scf.forall (%i) in (%ub) {
+    func.call @callee(%i) : (index) -> ()
+  }
+  return %0 : tensor<1xf32>
+}



More information about the Mlir-commits mailing list