[Mlir-commits] [mlir] [mlir][tensor] Fix PadOp::getConstantPaddingValue (PR #121205)
Longsheng Mou
llvmlistbot at llvm.org
Mon Dec 30 18:31:03 PST 2024
CoTinker wrote:
> Makes sense, thanks. I've left a couple of minor comments.
>
> Side comment - the test that's been added could quite easily be lowered to `linalg.fill`. Unless I am missing sth? If that's the case, lets leave a TODO somewhere. Probably near the test.
Actually, the constant value inside the PadOp can canonicalize to the outside, such as:
```
// mlir-opt --canonicalize
func.func @generalize_pad_tensor_constant_inside(%arg0: tensor<1x28x28x1xf32>) -> tensor<1x32x32x1xf32> {
%0 = tensor.pad %arg0 low[0, 2, 2, 0] high[0, 2, 2, 0] {
^bb0(%arg1: index, %arg2: index, %arg3: index, %arg4: index):
%cst = arith.constant 0.000000e+00 : f32
tensor.yield %cst : f32
} : tensor<1x28x28x1xf32> to tensor<1x32x32x1xf32>
return %0 : tensor<1x32x32x1xf32>
}
--->
func.func @generalize_pad_tensor_constant_inside(%arg0: tensor<1x28x28x1xf32>) -> tensor<1x32x32x1xf32> {
%cst = arith.constant 0.000000e+00 : f32
%padded = tensor.pad %arg0 low[0, 2, 2, 0] high[0, 2, 2, 0] {
^bb0(%arg1: index, %arg2: index, %arg3: index, %arg4: index):
tensor.yield %cst : f32
} : tensor<1x28x28x1xf32> to tensor<1x32x32x1xf32>
return %padded : tensor<1x32x32x1xf32>
}
```
https://github.com/llvm/llvm-project/pull/121205
More information about the Mlir-commits
mailing list