[Mlir-commits] [mlir] [mlir][tosa] Disallow boolean as element type for Clamp (PR #149312)
Longsheng Mou
llvmlistbot at llvm.org
Thu Jul 17 06:50:06 PDT 2025
https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/149312
According to TOSA spec, clamp op not support boolean type, and the verification and lowering of clamp with boolean type are incorrect. This PR disallow boolean as element type for `tosa.clamp` to avoid mistake. Fixes #130016.
>From be86b3b2479df39f84acdbd5994f776d7281b209 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Thu, 17 Jul 2025 21:40:31 +0800
Subject: [PATCH] [mlir][tosa] Disallow boolean as element type for Clamp
According to TOSA spec, clamp op not support boolean type,
and the verification and lowering of clamp with boolean type
are incorrect. This PR disallow boolean as element type for
`tosa.clamp` to avoid mistake.
---
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 3 +++
mlir/test/Dialect/Tosa/invalid.mlir | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index f0ff430bae882..d3a0b290c0610 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -928,6 +928,9 @@ LogicalResult tosa::ClampOp::verify() {
if (inputETy != outputETy)
return emitOpError("input/output element types are incompatible.");
+ if (inputETy.isInteger(1))
+ return emitOpError("does not support boolean element types.");
+
auto maxValAttr = getMaxValAttr();
auto minValAttr = getMinValAttr();
diff --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir
index 5a424c41775c9..1f1e4159414f4 100644
--- a/mlir/test/Dialect/Tosa/invalid.mlir
+++ b/mlir/test/Dialect/Tosa/invalid.mlir
@@ -750,6 +750,15 @@ func.func @test_mismatch_in_out_shape_clamp(%arg0: tensor<13x21x3xf32>) -> tenso
// -----
+// CHECK-LABEL: test_unsupported_boolean_type_clamp
+func.func @test_unsupported_boolean_type_clamp(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi1> {
+ // expected-error at +1 {{'tosa.clamp' op does not support boolean element types}}
+ %0 = tosa.clamp %arg0 {min_val = false, max_val = true} : (tensor<13x21x3xi1>) -> tensor<13x21x3xi1>
+ return %0 : tensor<13x21x3xi1>
+}
+
+// -----
+
// CHECK-LABEL: test_mismatch_in_out_data_type_erf
func.func @test_mismatch_in_out_data_type_erf(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> {
// expected-error at +1 {{'tosa.erf' op requires the same element type for all operands and results}}
More information about the Mlir-commits
mailing list