[Mlir-commits] [mlir] e5b2be3 - [mlir][tosa] Switch arith::ConstantOp to tosa::ConstOp for optimized Transpose perms parameter (#124945)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jan 30 09:08:16 PST 2025
Author: Thibaut Goetghebuer-Planchon
Date: 2025-01-30T09:08:12-08:00
New Revision: e5b2be3a27946d730de390fe92a53b04bc38a435
URL: https://github.com/llvm/llvm-project/commit/e5b2be3a27946d730de390fe92a53b04bc38a435
DIFF: https://github.com/llvm/llvm-project/commit/e5b2be3a27946d730de390fe92a53b04bc38a435.diff
LOG: [mlir][tosa] Switch arith::ConstantOp to tosa::ConstOp for optimized Transpose perms parameter (#124945)
When consolidating transpose ops into one, use `tosa::ConstOp` for the
permutations parameter instead of `arith::ConstantOp`.
Added:
Modified:
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
mlir/test/Dialect/Tosa/transpose-fold.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 98871268e313b6..9d36947b4352bb 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -111,8 +111,8 @@ struct ConsolidateTransposeOptimization
auto permsTy =
RankedTensorType::get(transposePerms.size(), rewriter.getI32Type());
auto permsAttr = DenseIntElementsAttr::get(permsTy, perms);
- Value permsValue =
- rewriter.create<arith::ConstantOp>(transposeOp.getLoc(), permsAttr);
+ Value permsValue = rewriter.create<tosa::ConstOp>(transposeOp.getLoc(),
+ permsTy, permsAttr);
rewriter.replaceOpWithNewOp<tosa::TransposeOp>(
transposeOp, transposeOp.getResult().getType(),
diff --git a/mlir/test/Dialect/Tosa/transpose-fold.mlir b/mlir/test/Dialect/Tosa/transpose-fold.mlir
index 3e57d7ff618f69..a7e9982c8db707 100644
--- a/mlir/test/Dialect/Tosa/transpose-fold.mlir
+++ b/mlir/test/Dialect/Tosa/transpose-fold.mlir
@@ -6,9 +6,9 @@
// CHECK: }
func.func @test_cancel_transpose_transpose(%arg0: tensor<1x2x3xi32>) -> (tensor<1x2x3xi32>) {
- %0 = arith.constant dense<[1, 2, 0]> : tensor<3xi32>
+ %0 = "tosa.const"() {value = dense<[1, 2, 0]> : tensor<3xi32>} : () -> tensor<3xi32>
%1 = tosa.transpose %arg0, %0 : (tensor<1x2x3xi32>, tensor<3xi32>) -> tensor<2x3x1xi32>
- %2 = arith.constant dense<[2, 0, 1]> : tensor<3xi32>
+ %2 = "tosa.const"() {value = dense<[2, 0, 1]> : tensor<3xi32>} : () -> tensor<3xi32>
%3 = tosa.transpose %1, %2 : (tensor<2x3x1xi32>, tensor<3xi32>) -> tensor<1x2x3xi32>
return %3 : tensor<1x2x3xi32>
}
@@ -21,7 +21,7 @@ func.func @test_cancel_transpose_transpose(%arg0: tensor<1x2x3xi32>) -> (tensor<
// CHECK: }
func.func @test_remove_identity_transpose(%arg0: tensor<1x2x3xi32>) -> (tensor<1x2x3xi32>) {
- %0 = arith.constant dense<[0, 1, 2]> : tensor<3xi32>
+ %0 = "tosa.const"() {value = dense<[0, 1, 2]> : tensor<3xi32>} : () -> tensor<3xi32>
%1 = tosa.transpose %arg0, %0 : (tensor<1x2x3xi32>, tensor<3xi32>) -> tensor<1x2x3xi32>
return %1 : tensor<1x2x3xi32>
}
@@ -30,15 +30,15 @@ func.func @test_remove_identity_transpose(%arg0: tensor<1x2x3xi32>) -> (tensor<1
// CHECK-LABEL: func.func @test_do_not_cancel_
diff erent_transpose(
// CHECK-SAME: %[[VAL_0:.*]]: tensor<2x3x4x5xi32>) -> tensor<5x4x3x2xi32> {
-// CHECK: %[[VAL_1:.*]] = arith.constant dense<[3, 2, 1, 0]> : tensor<4xi32>
+// CHECK: %[[VAL_1:.*]] = "tosa.const"() <{value = dense<[3, 2, 1, 0]> : tensor<4xi32>}> : () -> tensor<4xi32>
// CHECK: %[[VAL_2:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_1]] : (tensor<2x3x4x5xi32>, tensor<4xi32>) -> tensor<5x4x3x2xi32>
// CHECK: return %[[VAL_2]] : tensor<5x4x3x2xi32>
// CHECK: }
func.func @test_do_not_cancel_
diff erent_transpose(%arg0: tensor<2x3x4x5xi32>) -> (tensor<5x4x3x2xi32>) {
- %0 = arith.constant dense<[1, 2, 0, 3]> : tensor<4xi32>
+ %0 = "tosa.const"() {value = dense<[1, 2, 0, 3]> : tensor<4xi32>} : () -> tensor<4xi32>
%1 = tosa.transpose %arg0, %0 : (tensor<2x3x4x5xi32>, tensor<4xi32>) -> tensor<3x4x2x5xi32>
- %2 = arith.constant dense<[3, 1, 0, 2]> : tensor<4xi32>
+ %2 = "tosa.const"() {value = dense<[3, 1, 0, 2]> : tensor<4xi32>} : () -> tensor<4xi32>
%3 = tosa.transpose %1, %2 : (tensor<3x4x2x5xi32>, tensor<4xi32>) -> tensor<5x4x3x2xi32>
return %3 : tensor<5x4x3x2xi32>
}
@@ -47,15 +47,15 @@ func.func @test_do_not_cancel_
diff erent_transpose(%arg0: tensor<2x3x4x5xi32>) ->
// CHECK-LABEL: func.func @test_prefer_compose_transpose(
// CHECK-SAME: %[[VAL_0:.*]]: tensor<1x2x3x4xi32>) -> tensor<4x3x2x1xi32> {
-// CHECK: %[[VAL_1:.*]] = arith.constant dense<[3, 2, 1, 0]> : tensor<4xi32>
+// CHECK: %[[VAL_1:.*]] = "tosa.const"() <{value = dense<[3, 2, 1, 0]> : tensor<4xi32>}> : () -> tensor<4xi32>
// CHECK: %[[VAL_2:.*]] = tosa.transpose %[[VAL_0]], %[[VAL_1]] : (tensor<1x2x3x4xi32>, tensor<4xi32>) -> tensor<4x3x2x1xi32>
// CHECK: return %[[VAL_2]] : tensor<4x3x2x1xi32>
// CHECK: }
func.func @test_prefer_compose_transpose(%arg0: tensor<1x2x3x4xi32>) -> (tensor<4x3x2x1xi32>) {
- %0 = arith.constant dense<[1, 2, 0, 3]> : tensor<4xi32>
+ %0 = "tosa.const"() {value = dense<[1, 2, 0, 3]> : tensor<4xi32>} : () -> tensor<4xi32>
%1 = tosa.transpose %arg0, %0 : (tensor<1x2x3x4xi32>, tensor<4xi32>) -> tensor<2x3x1x4xi32>
- %2 = arith.constant dense<[3, 1, 0, 2]> : tensor<4xi32>
+ %2 = "tosa.const"() {value = dense<[3, 1, 0, 2]> : tensor<4xi32>} : () -> tensor<4xi32>
%3 = tosa.transpose %1, %2 : (tensor<2x3x1x4xi32>, tensor<4xi32>) -> tensor<4x3x2x1xi32>
return %3 : tensor<4x3x2x1xi32>
}
More information about the Mlir-commits
mailing list