[Mlir-commits] [mlir] [mlir][tosa] Fix intdiv folder type equality check (PR #180763)
Luke Hutton
llvmlistbot at llvm.org
Tue Feb 10 08:03:44 PST 2026
https://github.com/lhutton1 created https://github.com/llvm/llvm-project/pull/180763
The folder was incorrectly checking the tensor types for equality as opposed to the element types.
cc @udaya-ranga
>From 2028075cf0470031079c1f9f70e6944fce8a1e83 Mon Sep 17 00:00:00 2001
From: Luke Hutton <luke.hutton at arm.com>
Date: Tue, 10 Feb 2026 15:58:03 +0000
Subject: [PATCH] [mlir][tosa] Fix intdiv folder type equality check
The folder was incorrectly checking the tensor types
for equality as opposed to the element types.
Change-Id: I49e7bf4c134d9fb43e98e5f13b8eef647194c70a
---
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp | 5 ++++-
mlir/test/Dialect/Tosa/constant_folding.mlir | 10 +++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 42033ce8a3b02..a33ecb8511a92 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -1247,7 +1247,10 @@ OpFoldResult IntDivOp::fold(FoldAdaptor adaptor) {
auto resultTy = llvm::dyn_cast<RankedTensorType>(getType());
if (!lhsTy || !rhsTy || !resultTy)
return {};
- if (lhsTy != rhsTy)
+
+ const Type lhsETy = lhsTy.getElementType();
+ const Type rhsETy = rhsTy.getElementType();
+ if (lhsETy != rhsETy)
return {};
// IntDivOp inputs must be integer type, no need to check for quantized type
diff --git a/mlir/test/Dialect/Tosa/constant_folding.mlir b/mlir/test/Dialect/Tosa/constant_folding.mlir
index c3186279a30ae..56425e2feb0dd 100644
--- a/mlir/test/Dialect/Tosa/constant_folding.mlir
+++ b/mlir/test/Dialect/Tosa/constant_folding.mlir
@@ -158,13 +158,13 @@ func.func @fold_div_one_rhs_i32(%arg0: tensor<i32>) -> tensor<i32> {
// -----
// CHECK-LABEL: @fold_div_splat_i32
-func.func @fold_div_splat_i32() -> tensor<i32> {
- %lhs = "tosa.const"() {values = dense<10> : tensor<i32>} : () -> tensor<i32>
- %rhs = "tosa.const"() {values = dense<-3> : tensor<i32>} : () -> tensor<i32>
+func.func @fold_div_splat_i32() -> tensor<3x2xi32> {
+ %lhs = "tosa.const"() {values = dense<10> : tensor<1x2xi32>} : () -> tensor<1x2xi32>
+ %rhs = "tosa.const"() {values = dense<-3> : tensor<3x1xi32>} : () -> tensor<3x1xi32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-3>
- %div = tosa.intdiv %lhs, %rhs : (tensor<i32>, tensor<i32>) -> tensor<i32>
+ %div = tosa.intdiv %lhs, %rhs : (tensor<1x2xi32>, tensor<3x1xi32>) -> tensor<3x2xi32>
// CHECK: return %[[SPLAT]]
- return %div : tensor<i32>
+ return %div : tensor<3x2xi32>
}
// -----
More information about the Mlir-commits
mailing list