[Mlir-commits] [mlir] [mlir][linalg] Add test for ReduceOp empty-input verifier; remove dead empty-output check (PR #189614)
Mehdi Amini
llvmlistbot at llvm.org
Tue Mar 31 04:27:49 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/189614
Add a FileCheck test covering the 'expected at least one input' error in ReduceOp::verify(). The companion 'expected at least one output' check was dead code: SameVariadicOperandSize fires first whenever inputs.size() \!= inits.size(), and when both are empty the input check fires first; remove the unreachable branch.
Assisted-by: Claude Code
>From af3316e8223a8718a1d59f3ffe4b0c2d9a9d4e5a Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Tue, 31 Mar 2026 04:26:51 -0700
Subject: [PATCH] [mlir][linalg] Add test for ReduceOp empty-input verifier;
remove dead empty-output check
Add a FileCheck test covering the 'expected at least one input' error
in ReduceOp::verify(). The companion 'expected at least one output'
check was dead code: SameVariadicOperandSize fires first whenever
inputs.size() \!= inits.size(), and when both are empty the input check
fires first; remove the unreachable branch.
Assisted-by: Claude Code
---
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 2 --
mlir/test/Dialect/Linalg/invalid.mlir | 12 ++++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index e9698365765e7..f9c8589683ba7 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -1897,8 +1897,6 @@ LogicalResult ReduceOp::verify() {
if (getInputs().empty())
return emitOpError() << "expected at least one input";
- if (getInits().empty())
- return emitOpError() << "expected at least one output";
for (int64_t i = 1; i < getNumDpsInputs(); ++i) {
if (llvm::cast<ShapedType>(getInputs()[i].getType()).getShape() !=
diff --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir
index d9192cbda14e7..25dba5d11cc77 100644
--- a/mlir/test/Dialect/Linalg/invalid.mlir
+++ b/mlir/test/Dialect/Linalg/invalid.mlir
@@ -2194,3 +2194,15 @@ func.func @reduce_unequal_input_output_count(
%ext = tensor.extract %reduced[] : tensor<i32>
return %ext : i32
}
+
+// -----
+
+func.func @reduce_no_inputs() {
+ // expected-error @+1 {{'linalg.reduce' op expected at least one input}}
+ linalg.reduce
+ dimensions = []
+ () {
+ linalg.yield
+ }
+ func.return
+}
More information about the Mlir-commits
mailing list