[Mlir-commits] [mlir] [MLIR][Linalg] Diagnose unsupported types in Linalg named op region builders (PR #181616)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 17 17:49:23 PST 2026
https://github.com/shubhamnarlawar updated https://github.com/llvm/llvm-project/pull/181616
>From 0814ec78337e64052b1d35127abf58d5accb0197 Mon Sep 17 00:00:00 2001
From: Shubham Narlawar <shubham.narlawar at rrlogic.co.in>
Date: Mon, 16 Feb 2026 14:31:30 +0530
Subject: [PATCH] [MLIR][Linalg] Diagnose unsupported types in Linalg named op
region builders
Plumb emitError callbacks through Linalg named op region builders so
RegionBuilderHelper emits diagnostics instead of hitting llvm_unreachable
for unsupported operand element types (e.g. amx.tile).
Update linalg/invalid.mlir to add functions - linalg.batch_matmul(), linalg.batch_reduce_matmul()
and linalg.matmul() with amx.tile operands to ensure mlir-opt fails gracefully without crash.
Fixes #179677
---
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 20 +++++++++++++-----
mlir/test/Dialect/Linalg/invalid.mlir | 26 ++++++++++++++++++++++++
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index eba3fa6db2126..161bdaaf5bc6c 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -3877,7 +3877,7 @@ void MatmulOp::regionBuilder(ImplicitLocOpBuilder &b, Block &block,
Value value2 = helper.buildTypeFn(castVal, block.getArgument(2).getType(),
block.getArgument(1));
Value value3 = helper.buildBinaryFn(BinaryFn::mul, value1, value2, emitError);
- if (!value3)
+ if (!value1 || !value2 || !value3)
return;
Value value4 = helper.buildBinaryFn(BinaryFn::add, block.getArgument(2),
value3, emitError);
@@ -4648,9 +4648,14 @@ void BatchMatmulOp::regionBuilder(
auto toType = block.getArgument(2).getType();
Value castValA = helper.buildTypeFn(castVal, toType, block.getArgument(0));
Value castValB = helper.buildTypeFn(castVal, toType, block.getArgument(1));
- Value mulVal = helper.buildBinaryFn(BinaryFn::mul, castValA, castValB);
- Value addVal =
- helper.buildBinaryFn(BinaryFn::add, block.getArgument(2), mulVal);
+ Value mulVal =
+ helper.buildBinaryFn(BinaryFn::mul, castValA, castValB, emitError);
+ if (!castValA || !castValB || !mulVal)
+ return;
+ Value addVal = helper.buildBinaryFn(BinaryFn::add, block.getArgument(2),
+ mulVal, emitError);
+ if (!addVal)
+ return;
yields.push_back(addVal);
helper.yieldOutputs(yields);
}
@@ -6586,9 +6591,14 @@ void BatchReduceMatmulOp::regionBuilder(
helper.buildTypeFn(TypeFn::cast_signed, toType, block.getArgument(0));
Value castValB =
helper.buildTypeFn(TypeFn::cast_signed, toType, block.getArgument(1));
- Value mulVal = helper.buildBinaryFn(BinaryFn::mul, castValA, castValB);
+ Value mulVal =
+ helper.buildBinaryFn(BinaryFn::mul, castValA, castValB, emitError);
+ if (!castValA || !castValB || !mulVal)
+ return;
Value addVal =
helper.buildBinaryFn(BinaryFn::add, block.getArgument(2), mulVal);
+ if (!addVal)
+ return;
yields.push_back(addVal);
helper.yieldOutputs(yields);
}
diff --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir
index 355d801f8732c..01c280f071bf1 100644
--- a/mlir/test/Dialect/Linalg/invalid.mlir
+++ b/mlir/test/Dialect/Linalg/invalid.mlir
@@ -617,6 +617,15 @@ func.func @invalid_indexing_maps_placement_matmul(%lhs: tensor<4x1xf32>, %rhs: t
// -----
+func.func @invalid_type_matmul(%arg0 : !amx.tile<16x16xbf16>)
+{
+ // expected-error @below {{custom op 'linalg.matmul' Cannot build binary Linalg operation: expects allComplex, allFloatingPoint, or allInteger, got '!amx.tile<16x16xbf16>' and '!amx.tile<16x16xbf16>'}}
+ %0 = linalg.matmul ins(%arg0, %arg0 : !amx.tile<16x16xbf16>, !amx.tile<16x16xbf16>) outs(%arg0 : !amx.tile<16x16xbf16>) -> !amx.tile<16x16xbf16>
+ return
+}
+
+// -----
+
func.func @invalid_indexing_maps_placement_contraction(
%lhs: tensor<4x1xf32>, %rhs: tensor<1x64xf32>, %init: tensor<4x64xf32>) {
// expected-error @+3 {{custom op 'linalg.contract' expected 'indexing_maps' attribute}}
@@ -1553,6 +1562,14 @@ func.func @invalid_C_map_result_dim_batch_matmul(%arg0: memref<?x?x?xf32>, %arg1
return
}
+// -----
+
+func.func @invalid_type_batch_matmul(%arg0 : !amx.tile<16x16xbf16>)
+{
+ // expected-error @below {{custom op 'linalg.batch_matmul' Cannot build binary Linalg operation: expects allComplex, allFloatingPoint, or allInteger, got '!amx.tile<16x16xbf16>' and '!amx.tile<16x16xbf16>'}}
+ %0 = linalg.batch_matmul ins(%arg0, %arg0 : !amx.tile<16x16xbf16>, !amx.tile<16x16xbf16>) outs(%arg0 : !amx.tile<16x16xbf16>) -> !amx.tile<16x16xbf16>
+ return
+}
// -----
@@ -1755,6 +1772,15 @@ func.func @invalid_C_map_result_dim(%A: memref<?x?x?xf32>, %B: memref<?x?x?xf32>
// -----
+func.func @batch_reduce_matmul_invalid_type(%arg0 : !amx.tile<16x16xbf16>)
+{
+ // expected-error @below {{custom op 'linalg.batch_reduce_matmul' Cannot build binary Linalg operation: expects allComplex, allFloatingPoint, or allInteger, got '!amx.tile<16x16xbf16>' and '!amx.tile<16x16xbf16>'}}
+ %0 = linalg.batch_reduce_matmul ins(%arg0, %arg0 : !amx.tile<16x16xbf16>, !amx.tile<16x16xbf16>) outs(%arg0 : !amx.tile<16x16xbf16>) -> !amx.tile<16x16xbf16>
+ return
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// linalg.pack
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list