Skip to content

Conversation

@ShivaChen
Copy link
Collaborator

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.

Would there have better way to fix the issue?

@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2025

@llvm/pr-subscribers-mlir-tosa

@llvm/pr-subscribers-mlir

Author: None (ShivaChen)

Changes

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.

Would there have better way to fix the issue?


Full diff: https://github.com/llvm/llvm-project/pull/163312.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td (-1)
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.";
 

Copy link
Contributor

@lhutton1 lhutton1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @ShivaChen, is it possible to add a test at all?

@lhutton1 lhutton1 changed the title [RFC][mlir][tosa] Remove Tosa MulOp Commutative attribute [mlir][tosa] Remove Tosa MulOp Commutative attribute Oct 16, 2025
@ShivaChen ShivaChen force-pushed the remove-tosa-mul-commutative branch from 2af0037 to 497caac Compare October 20, 2025 05:29
@ShivaChen
Copy link
Collaborator Author

Thanks for the fix @ShivaChen, is it possible to add a test at all?

Hi @lhutton1, I added no_shift_op_reorder to check that tosa-layerwise-constant-fold pass won't reorder the shift operand.
Thanks for the advice. :-)

Copy link
Contributor

@lhutton1 lhutton1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test @ShivaChen, just had a small nitpick before merging


// 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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing a CHECK-LABEL line here

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.
@ShivaChen ShivaChen force-pushed the remove-tosa-mul-commutative branch from 9dd5283 to 959e89d Compare October 21, 2025 01:34
@ShivaChen ShivaChen merged commit 69d97a6 into llvm:main Oct 21, 2025
10 checks passed
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
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?
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants