[Mlir-commits] [mlir] [mlir][tosa] Fold tensor.cast into tosa.transpose (PR #170029)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Nov 30 01:28:16 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 6d1e46014..f2c5b2c01 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -442,7 +442,7 @@ struct TransposeOpCastFolder : public OpRewritePattern<tosa::TransposeOp> {
     if (!tensor::hasFoldableTensorCastOperand(transposeOp))
       return rewriter.notifyMatchFailure(transposeOp,
                                          "no foldable cast operand");
-    
+
     auto castOp = cast<tensor::CastOp>(transposeOp.getInput1().getDefiningOp());
     auto srcType = cast<RankedTensorType>(castOp.getSource().getType());
     auto oldResultType = cast<RankedTensorType>(transposeOp.getType());
@@ -456,11 +456,12 @@ struct TransposeOpCastFolder : public OpRewritePattern<tosa::TransposeOp> {
       newShape.push_back(srcType.getDimSize(perm));
     auto newResultType = RankedTensorType::get(
         newShape, srcType.getElementType(), srcType.getEncoding());
-    auto newTransposeOp = tosa::TransposeOp::create(
-        rewriter, transposeOp.getLoc(), newResultType, castOp.getSource(), perms);
-    
-    rewriter.replaceOpWithNewOp<tensor::CastOp>(
-        transposeOp, oldResultType, newTransposeOp);
+    auto newTransposeOp =
+        tosa::TransposeOp::create(rewriter, transposeOp.getLoc(), newResultType,
+                                  castOp.getSource(), perms);
+
+    rewriter.replaceOpWithNewOp<tensor::CastOp>(transposeOp, oldResultType,
+                                                newTransposeOp);
     return success();
   }
 };

``````````

</details>


https://github.com/llvm/llvm-project/pull/170029


More information about the Mlir-commits mailing list