[Mlir-commits] [mlir] d48b730 - [mlir][tosa] Move MUL shift value check out of verifier (#234063)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Oct 23 00:58:22 PDT 2026


Author: Akun
Date: 2026-10-23T08:58:16+01:00
New Revision: d48b7304aeb9237b830607cb4e01ce4ea0a2f9bf

URL: https://github.com/llvm/llvm-project/commit/d48b7304aeb9237b830607cb4e01ce4ea0a2f9bf
DIFF: https://github.com/llvm/llvm-project/commit/d48b7304aeb9237b830607cb4e01ce4ea0a2f9bf.diff

LOG: [mlir][tosa] Move MUL shift value check out of verifier (#234063)

Keep `MulOp::verify()` local to the operation by removing its constant
`shift` value check. The existing strict `tosa-validate` check covers
invalid shift values.

Move the floating-point shift regression test to `error_if_check.mlir`.

Assisted-by: Codex

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
    mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
    mlir/test/Dialect/Tosa/error_if_check.mlir
    mlir/test/Dialect/Tosa/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
index faf29f374b3875..4458dae5f06e8e 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
@@ -1246,7 +1246,10 @@ def Tosa_MulOp : Tosa_Op<"mul", [
     Axis of size 1 will be broadcast, as necessary. Rank of input tensors must
     match.
 
-    This operation is not pure. Undefined behaviour may occur if the specifed
+    For int32_t input data, shift must be in the range [0, 63]. For all other
+    input data types, shift must be 0.
+
+    This operation is not pure. Undefined behaviour may occur if the specified
     shift is out of range or the result overflows.
   }];
 

diff  --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 99c352ab8ed3c3..6b6f295c625f5b 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -2561,15 +2561,6 @@ LogicalResult tosa::MulOp::verify() {
         return emitOpError(
             "requires the same element type for all operands and results");
     }
-
-    // verify shift has value 0 for non-integer types
-    ElementsAttr shiftElem;
-    if (matchPattern(getShift(), m_Constant(&shiftElem))) {
-      int32_t shift = shiftElem.getValues<IntegerAttr>()[0].getInt();
-      if (shift != 0) {
-        return emitOpError() << "require shift to be 0 for float type";
-      }
-    }
   }
 
   // Verify the op has same ranks for all main operands (excludes extra operands

diff  --git a/mlir/test/Dialect/Tosa/error_if_check.mlir b/mlir/test/Dialect/Tosa/error_if_check.mlir
index b87f124f64ac27..39c023b3726fe8 100644
--- a/mlir/test/Dialect/Tosa/error_if_check.mlir
+++ b/mlir/test/Dialect/Tosa/error_if_check.mlir
@@ -146,6 +146,16 @@ func.func @test_mul_non_zero_shift(%arg0: tensor<1x8x8x8xi16>, %arg1: tensor<1x8
   return %mul : tensor<1x8x8x8xi32>
 }
 
+// -----
+
+// CHECK-LABEL: test_mul_invalid_shift
+func.func @test_mul_invalid_shift(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf32>) -> tensor<13x21x3xf32> {
+  %shift = "tosa.const"() <{values = dense<1> : tensor<1xi8>}> : () -> tensor<1xi8>
+  // expected-error at +1 {{'tosa.mul' op requires shift = 0 for all input data types that are not int32_t, but got: 1}}
+  %0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf32>, tensor<1xi8>) -> tensor<13x21x3xf32>
+  return %0 : tensor<13x21x3xf32>
+}
+
 // -----
 // CHECK-LABEL: test_i16_table_size
 func.func @test_i16_table_size(%arg0: tensor<2x64xi16>, %arg1: tensor<256xi16>) -> tensor<2x64xi32> {

diff  --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir
index bf05491164f404..1973736b28b222 100644
--- a/mlir/test/Dialect/Tosa/invalid.mlir
+++ b/mlir/test/Dialect/Tosa/invalid.mlir
@@ -637,16 +637,6 @@ func.func @test_mul_int_type_mismatch(%arg0: tensor<1xf32>, %arg1: tensor<1xf32>
 
 // -----
 
-// CHECK-LABEL: test_mul_invalid_shift
-func.func @test_mul_invalid_shift(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf32>) -> tensor<13x21x3xf32> {
-  %shift = "tosa.const"() <{values = dense<1> : tensor<1xi8>}> : () -> tensor<1xi8>
-  // expected-error at +1 {{'tosa.mul' op require shift to be 0 for float type}}
-  %0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xf32>, tensor<13x1x3xf32>, tensor<1xi8>) -> tensor<13x21x3xf32>
-  return %0 : tensor<13x21x3xf32>
-}
-
-// -----
-
 // CHECK-LABEL: test_mul_missing_shift
 func.func @test_mul_missing_shift(%arg0: tensor<13x21x3xi32>, %arg1: tensor<13x1x3xi32>) -> tensor<13x21x3xi32> {
   // expected-error at +1 {{'tosa.mul' op expected 3 operands, but found 2}}


        


More information about the Mlir-commits mailing list