[Mlir-commits] [mlir] [MLIR][TOSA] Add missing SameOperandsAndResultShape Trait to tosa.cast (PR #153826)
Jonas Rickert
llvmlistbot at llvm.org
Fri Aug 15 08:57:59 PDT 2025
https://github.com/jorickert created https://github.com/llvm/llvm-project/pull/153826
None
>From fe571857b31cab87007c38067e7be21cc1ab21d9 Mon Sep 17 00:00:00 2001
From: "Rickert, Jonas" <Jonas.Rickert at amd.com>
Date: Tue, 12 Aug 2025 16:04:42 +0100
Subject: [PATCH] Add missing SameOperandsAndResultShape Trait to tosa.cast
Signed-off-by: Rickert, Jonas <jonas.rickert at amd.com>
---
mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td | 2 +-
mlir/test/Dialect/Tosa/canonicalize.mlir | 14 ++++++--------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
index 20889558be314..416df6e87b11f 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
@@ -2247,7 +2247,7 @@ def Tosa_ResizeOp : Tosa_InferShapedTypeOp<"resize"> {
//===----------------------------------------------------------------------===//
// Operator: cast
//===----------------------------------------------------------------------===//
-def Tosa_CastOp: Tosa_Op<"cast", [Pure,
+def Tosa_CastOp: Tosa_Op<"cast", [Pure, SameOperandsAndResultShape,
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>]> {
diff --git a/mlir/test/Dialect/Tosa/canonicalize.mlir b/mlir/test/Dialect/Tosa/canonicalize.mlir
index 930bb9fe96811..b6d68c94f436b 100644
--- a/mlir/test/Dialect/Tosa/canonicalize.mlir
+++ b/mlir/test/Dialect/Tosa/canonicalize.mlir
@@ -1304,10 +1304,9 @@ func.func nested @fold_reciprocal() -> tensor<3x600x1200xf32> {
// CHECK: %[[VAL_0:.*]] = "tosa.const"() <{values = dense<8.620690e-03> : tensor<3x600x1200xf32>}> : () -> tensor<3x600x1200xf32>
// CHECK: return %[[VAL_0]] : tensor<3x600x1200xf32>
// CHECK: }
- %0 = "tosa.const"(){ values = dense<116.0>: tensor<f32> }: () -> tensor<f32>
- %1 = "tosa.cast"(%0) : (tensor<f32>) -> tensor<3x600x1200xf32>
- %2 = "tosa.reciprocal"(%1): (tensor<3x600x1200xf32>) -> tensor<3x600x1200xf32>
- return %2 : tensor<3x600x1200xf32>
+ %0 = "tosa.const"(){ values = dense<116.0>: tensor<3x600x1200xf32> }: () -> tensor<3x600x1200xf32>
+ %1 = "tosa.reciprocal"(%0): (tensor<3x600x1200xf32>) -> tensor<3x600x1200xf32>
+ return %1 : tensor<3x600x1200xf32>
}
// -----
@@ -1315,10 +1314,9 @@ func.func nested @fold_reciprocal() -> tensor<3x600x1200xf32> {
// CHECK-LABEL: @do_not_fold_reciprocal_int
func.func nested @do_not_fold_reciprocal_int() -> tensor<3x600x1200xi32> {
// CHECK: tosa.reciprocal
- %0 = "tosa.const"(){ values = dense<11>: tensor<i32> }: () -> tensor<i32>
- %1 = "tosa.cast"(%0) : (tensor<i32>) -> tensor<3x600x1200xi32>
- %2 = "tosa.reciprocal"(%1): (tensor<3x600x1200xi32>) -> tensor<3x600x1200xi32>
- return %2 : tensor<3x600x1200xi32>
+ %0 = "tosa.const"(){ values = dense<11>: tensor<3x600x1200xi32> }: () -> tensor<3x600x1200xi32>
+ %1 = "tosa.reciprocal"(%0): (tensor<3x600x1200xi32>) -> tensor<3x600x1200xi32>
+ return %1 : tensor<3x600x1200xi32>
}
// -----
More information about the Mlir-commits
mailing list