[Mlir-commits] [mlir] [mlir][linalg] Add splat transpose canonicalization patterns (PR #195991)
Hocky Yudhiono
llvmlistbot at llvm.org
Thu May 7 20:16:40 PDT 2026
================
@@ -2124,6 +2134,14 @@ LogicalResult TransposeOp::fold(FoldAdaptor adaptor,
return success();
}
+ if (getInput().getType() == getInit().getType()) {
----------------
hockyy wrote:
```mlir
func.func @transpose_splat_constant_same_shape_permutations(%arg0: tensor<3x3x3xf32>, %arg1: tensor<3x3x3xf32>) -> (tensor<3x3x3xf32>, tensor<3x3x3xf32>) {
%cst = arith.constant dense<1.000000e+00> : tensor<3x3x3xf32>
%transposed = linalg.transpose ins(%cst : tensor<3x3x3xf32>) outs(%arg0 : tensor<3x3x3xf32>) permutation = [0, 1, 2]
%transposed_0 = linalg.transpose ins(%cst : tensor<3x3x3xf32>) outs(%arg1 : tensor<3x3x3xf32>) permutation = [2, 0, 1]
return %transposed, %transposed_0 : tensor<3x3x3xf32>, tensor<3x3x3xf32>
}
```
I wanted to handle the case above in the fold, so, regardless of permutation maps, both can be folded. But now that we support the general canonicalization, I think the fold is redundant. I will just yeet out this `::fold` addition.
```mlir
func.func @transpose_splat_constant_same_shape_permutations(%arg0: tensor<3x3x3xf32>, %arg1: tensor<3x3x3xf32>) -> (tensor<3x3x3xf32>, tensor<3x3x3xf32>) {
%cst = arith.constant dense<1.000000e+00> : tensor<3x3x3xf32>
return %cst, %cst : tensor<3x3x3xf32>, tensor<3x3x3xf32>
}
```
https://github.com/llvm/llvm-project/pull/195991
More information about the Mlir-commits
mailing list