From dbf24a8f3428d34ab0746aad98ae2bdf4f35da69 Mon Sep 17 00:00:00 2001 From: Liang-Ta Wei Date: Wed, 16 Apr 2025 08:07:26 -0600 Subject: [PATCH 1/3] create tosa.constOp instead --- mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp index ea61718428477..a1bcc1217d701 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp @@ -370,7 +370,7 @@ struct ConsolidateTransposeOptimization RankedTensorType::get(transposePerms.size(), rewriter.getI32Type()); auto permsAttr = DenseIntElementsAttr::get(permsTy, perms); Value permsValue = - rewriter.create(transposeOp.getLoc(), permsAttr); + rewriter.create(transposeOp.getLoc(), permsTy, permsAttr); rewriter.replaceOpWithNewOp( transposeOp, transposeOp.getResult().getType(), From b94976312a8613784bda7c6c6b6aaeed9e45bfb0 Mon Sep 17 00:00:00 2001 From: Liang-Ta Wei Date: Wed, 16 Apr 2025 08:07:51 -0600 Subject: [PATCH 2/3] update lit tests --- mlir/test/Dialect/Tosa/transpose-fold.mlir | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mlir/test/Dialect/Tosa/transpose-fold.mlir b/mlir/test/Dialect/Tosa/transpose-fold.mlir index 3e57d7ff618f6..8a62cda1edc28 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_different_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_different_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_different_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> } From 90aa433ecb7105464be1a2dd4fb51a12970ac789 Mon Sep 17 00:00:00 2001 From: Liang-Ta Wei Date: Wed, 16 Apr 2025 08:19:26 -0600 Subject: [PATCH 3/3] clang format --- mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp index a1bcc1217d701..1bfc136d66431 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp @@ -369,8 +369,8 @@ struct ConsolidateTransposeOptimization auto permsTy = RankedTensorType::get(transposePerms.size(), rewriter.getI32Type()); auto permsAttr = DenseIntElementsAttr::get(permsTy, perms); - Value permsValue = - rewriter.create(transposeOp.getLoc(), permsTy, permsAttr); + Value permsValue = rewriter.create(transposeOp.getLoc(), + permsTy, permsAttr); rewriter.replaceOpWithNewOp( transposeOp, transposeOp.getResult().getType(),