[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:45:45 PST 2026


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

>From 0057d0223ae8d34cfd4ce53fb3f9dddea6dc8ab9 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      | 23 +++++++++++++++++++
 2 files changed, 29 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..f23a4dea670a2 100644
--- a/mlir/test/Dialect/SCF/forall-to-for.mlir
+++ b/mlir/test/Dialect/SCF/forall-to-for.mlir
@@ -55,3 +55,26 @@ func.func @nested(%ub1: index, %ub2: index, %ub3: index, %ub4: index) {
   }
   return
 }
+
+// -----
+
+// The pass should bail out cleanly and not crash. `scf.forall` with outputs is not
+// supported, but we should still handle the second variant of this op correctly here.
+
+func.func private @callee(%i: index, %j: index)
+
+// CHECK-LABEL: @shared_outs
+func.func @shared_outs(%arg0: tensor<1xf32>, %ub: index) -> tensor<1xf32> {
+  %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
+  // CHECK-NEXT:   scf.for
+  scf.forall (%i, %j) in (%ub, %ub) {
+    func.call @callee(%i, %j) : (index, index) -> ()
+  }
+  return %0 : tensor<1xf32>
+}



More information about the Mlir-commits mailing list