[Mlir-commits] [mlir] [mlir][tensor] Support padding with poison (PR #152003)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Aug 4 10:03:00 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-linalg
Author: James Newling (newling)
<details>
<summary>Changes</summary>
### Testing
In [this](https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp) file `pad_operand` is called by `rewriteAsPaddedOp` is called by `transform::PadTilingInterfaceOp::apply`. The only tests that reach `pad_operand` in MLIR are for example [this test](https://github.com/llvm/llvm-project/blob/main/mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir). It's not clear to me how to pass a poison attribute in there though. I've tried passing a string "poison" attribute and it hits logic [here](https://github.com/llvm/llvm-project/blob/37b6fbc95b7dd623c8cfff04af1f1b787cf3d4cd/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp#L1966). And without a string I can't get poison attribute to parse either. I don't see any examples in the test directory with poison attribute. Is this not a path we can use? i.e. I want an array attribute _like_ `padding_values= [poison, 0.0 : f32]`.
In IREE, I can see this works via a less targeted test using `applyPaddingLevel` in [this](https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/Common/GPU/GPUApplyPaddingLevel.cpp) file.
---
Full diff: https://github.com/llvm/llvm-project/pull/152003.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp (+12-6)
- (modified) mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir (+3-1)
``````````diff
diff --git a/mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp b/mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp
index 2e6252336dfeb..3d12bc397813b 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/PadTilingInterface.cpp
@@ -11,6 +11,7 @@
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
+#include "mlir/Dialect/UB/IR/UBOps.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/BuiltinAttributes.h"
@@ -230,13 +231,18 @@ static Value padOperand(RewriterBase &rewriter, TilingInterface opToPad,
Value paddingValue;
if (auto complexTy =
dyn_cast<ComplexType>(getElementTypeOrSelf(v.getType()))) {
- auto complexAttr = cast<ArrayAttr>(paddingValueAttr);
- paddingValue = complex::ConstantOp::create(rewriter, opToPad.getLoc(),
- complexTy, complexAttr);
- } else {
- paddingValue = arith::ConstantOp::create(rewriter, opToPad.getLoc(),
- cast<TypedAttr>(paddingValueAttr));
+ if (auto complexAttr = dyn_cast<ArrayAttr>(paddingValueAttr)) {
+ paddingValue = complex::ConstantOp::create(rewriter, opToPad.getLoc(),
+ complexTy, complexAttr);
+ }
+ } else if (isa<ub::PoisonAttr>(paddingValueAttr)) {
+ paddingValue = ub::PoisonOp::create(rewriter, opToPad.getLoc(),
+ getElementTypeOrSelf(v.getType()));
+ } else if (auto typedAttr = dyn_cast<TypedAttr>(paddingValueAttr)) {
+ paddingValue =
+ arith::ConstantOp::create(rewriter, opToPad.getLoc(), typedAttr);
}
+ assert(paddingValue && "failed to create value from padding attribute");
// Pad the operand to the bounding box defined by `paddedShape`.
SmallVector<int64_t> tensorShape;
diff --git a/mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir b/mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir
index f7418769f79ca..2857b53103779 100644
--- a/mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-pad-tiling-interface.mlir
@@ -4,6 +4,7 @@
// CHECK: linalg.fill ins(%{{.*}} : f32) outs(%{{.*}} : tensor<8x25xf32>) -> tensor<8x25xf32>
func.func @pad_fill(%value: f32, %output: tensor<24x25xf32>) -> tensor<24x25xf32>
{
+ // %goo = ub.poison : f32
%0 = linalg.fill ins(%value : f32) outs(%output : tensor<24x25xf32>) -> tensor<24x25xf32>
func.return %0 : tensor<24x25xf32>
}
@@ -18,7 +19,8 @@ module attributes {transform.with_named_sequence} {
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
%fill_padded, %_ = transform.structured.pad_tiling_interface %fill_l1 to padding_sizes [8] {
- padding_values=[0.0 : f32, 0.0 : f32]
+ // padding_values= [poison, 0.0 : f32]
+ padding_values= [0.0 : f32, 0.0 : f32]
} : (!transform.any_op) -> (!transform.any_op, !transform.any_op)
transform.yield
``````````
</details>
https://github.com/llvm/llvm-project/pull/152003
More information about the Mlir-commits
mailing list