[Mlir-commits] [mlir] 0a8ddd3 - [mlir][tosa] Interpret boolean values correctly (#149312)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jul 22 06:35:17 PDT 2025
Author: Longsheng Mou
Date: 2025-07-22T14:35:13+01:00
New Revision: 0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8
URL: https://github.com/llvm/llvm-project/commit/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8
DIFF: https://github.com/llvm/llvm-project/commit/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8.diff
LOG: [mlir][tosa] Interpret boolean values correctly (#149312)
Previously the `ClampOp::verify` would sign extend boolean values,
leading "true" to be casted to a value of -1 instead of 1. This PR
ensures i1 values are zero extended, since i1 is used as a boolean value
in TOSA.
Added:
Modified:
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
mlir/test/Dialect/Tosa/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 5b4a2c9d85ea1..648e508a9788f 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -945,10 +945,11 @@ LogicalResult tosa::ClampOp::verify() {
return emitOpError("min/max attributes types are incompatible with "
"input/output element types.");
- const bool isUnsigned = cast<IntegerType>(inputETy).isUnsigned();
+ const bool isUnsigned = inputETy.isUnsignedInteger();
+ const bool isBoolean = inputETy.isInteger(1);
const APInt minVal = intMinValAttr.getValue();
const APInt maxVal = intMaxValAttr.getValue();
- if (isUnsigned ? maxVal.ult(minVal) : maxVal.slt(minVal))
+ if ((isUnsigned || isBoolean) ? maxVal.ult(minVal) : maxVal.slt(minVal))
return emitOpError("expected min_val <= max_val, got min_val=")
<< minValAttr << ", max_val=" << maxValAttr;
} else {
diff --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir
index 5a424c41775c9..ed747145369d7 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 illegal: operation operand/result data types did not align with any profile or extension, got (i1,i1), did you mean (i8,i8)?}}
+ %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