[Mlir-commits] [mlir] 69d97a6 - [mlir][tosa] Remove Tosa MulOp Commutative attribute (#163312)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 20 18:49:11 PDT 2025


Author: ShivaChen
Date: 2025-10-21T09:49:07+08:00
New Revision: 69d97a6531bb36d620775159308915884b26eae6

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

LOG: [mlir][tosa] Remove Tosa MulOp Commutative attribute (#163312)

The patch motivates by following cases in Tosa Conformance Test.
conformance/operators/ew_binary/mul/mul_21x44_i8_perm0_shift0_dyn
conformance/operators/ew_binary/mul/mul_44x57_i16_perm0_shift0_dyn
conformance/operators/ew_binary/mul/mul_52x31_i32_perm0_shift8_dyn

Shift operand could be non-constant when dynamic extension enabled. With
Commutative attribute, all the operands would be treated as commutative.
Shift operand could be reordered with one of the MulOp inputs
incorrectly in above cases.

Would there have better way to fix the issue?

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
    mlir/test/Dialect/Tosa/constant-op-fold.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
index 48759f2a3c9e8..697a04e94441a 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
@@ -1027,7 +1027,6 @@ def Tosa_MinimumOp : Tosa_ElementwiseOp<"minimum", [
 def Tosa_MulOp : Tosa_Op<"mul", [
     DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
                               ["inferReturnTypeComponents"]>,
-    Commutative,
     Pure]> {
   let summary = "Multiplication operator.";
 

diff  --git a/mlir/test/Dialect/Tosa/constant-op-fold.mlir b/mlir/test/Dialect/Tosa/constant-op-fold.mlir
index d9d188dd25061..b1fbcdcc53e2f 100644
--- a/mlir/test/Dialect/Tosa/constant-op-fold.mlir
+++ b/mlir/test/Dialect/Tosa/constant-op-fold.mlir
@@ -1172,3 +1172,15 @@ func.func @reduce_sum_constant_aggressive() -> tensor<2x3xi32> {
   %res1 = tosa.add %res0, %argmax1 : (tensor<2x3xi32>, tensor<2x3xi32>) -> tensor<2x3xi32>
   return %res1 : tensor<2x3xi32>
 }
+
+// -----
+
+// no_shift_op_reorder checks that %arg1 won't be reorder with %0
+// by the folder pass.
+// CHECK-LABEL: @no_shift_op_reorder
+func.func @no_shift_op_reorder (%arg0 : tensor<44x1xi16>, %arg1 : tensor<1xi8>) -> tensor<44x57xi32> {
+  %0 = "tosa.const"() {values = dense<1> : tensor<44x57xi16>} : () -> tensor<44x57xi16>
+  // CHECK: tosa.mul %arg0, %0, %arg1
+  %1 = tosa.mul %arg0, %0, %arg1 : (tensor<44x1xi16>, tensor<44x57xi16>, tensor<1xi8>) -> tensor<44x57xi32>
+  return %1 : tensor<44x57xi32>
+}


        


More information about the Mlir-commits mailing list