[Mlir-commits] [mlir] [mlir][tosa] Remove Tosa MulOp Commutative attribute (PR #163312)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Oct 19 22:29:26 PDT 2025
https://github.com/ShivaChen updated https://github.com/llvm/llvm-project/pull/163312
>From f01ce2efba71dae94cb60b6baed966ae4b56d488 Mon Sep 17 00:00:00 2001
From: Shiva Chen <shiva.chen at imgtec.com>
Date: Tue, 14 Oct 2025 03:52:42 +0100
Subject: [PATCH 1/2] [RFC][mlir][tosa] Remove Tosa MulOp Commutative attribute
The patch motiviates 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.
---
mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td | 1 -
1 file changed, 1 deletion(-)
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.";
>From 497caaccad788e74648ac051cb980ee752fbb273 Mon Sep 17 00:00:00 2001
From: Shiva Chen <shiva.chen at imgtec.com>
Date: Mon, 20 Oct 2025 06:21:49 +0100
Subject: [PATCH 2/2] Add no_shift_op_reorder test case
---
mlir/test/Dialect/Tosa/constant-op-fold.mlir | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/mlir/test/Dialect/Tosa/constant-op-fold.mlir b/mlir/test/Dialect/Tosa/constant-op-fold.mlir
index d9d188dd25061..0e140ac1d3c6e 100644
--- a/mlir/test/Dialect/Tosa/constant-op-fold.mlir
+++ b/mlir/test/Dialect/Tosa/constant-op-fold.mlir
@@ -1172,3 +1172,14 @@ 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.
+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