[Mlir-commits] [mlir] [mlir] Fix `tensor.pad` to remote newly static values (PR #79938)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Jan 29 19:23:18 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Rob Suderman (rsuderman)
<details>
<summary>Changes</summary>
The canonicalization incrementally converts foldable dynamic hi/lo padding to static hi/lo values. During this canonicalization the static-fied valued should be removed from the dynamic values.
---
Full diff: https://github.com/llvm/llvm-project/pull/79938.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Tensor/IR/TensorOps.cpp (+5-1)
- (modified) mlir/test/Dialect/Tensor/canonicalize.mlir (+1-1)
``````````diff
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index b2fe58099b2fb..ff549c697c7fa 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -3158,19 +3158,23 @@ struct FoldStaticPadding : public OpRewritePattern<PadOp> {
// Extract the static info from the high and low operands.
SmallVector<int64_t> constOperandsLow;
+ llvm::SmallVector<Value> newLows;
for (auto operand : padTensorOp.getLow()) {
APSInt intOp;
if (!matchPattern(operand, m_ConstantInt(&intOp))) {
constOperandsLow.push_back(ShapedType::kDynamic);
+ newLows.push_back(operand);
continue;
}
constOperandsLow.push_back(intOp.getExtValue());
}
SmallVector<int64_t> constOperandsHigh;
+ llvm::SmallVector<Value> newHighs;
for (auto operand : padTensorOp.getHigh()) {
APSInt intOp;
if (!matchPattern(operand, m_ConstantInt(&intOp))) {
constOperandsHigh.push_back(ShapedType::kDynamic);
+ newHighs.push_back(operand);
continue;
}
constOperandsHigh.push_back(intOp.getExtValue());
@@ -3222,7 +3226,7 @@ struct FoldStaticPadding : public OpRewritePattern<PadOp> {
newOutDims, padTensorOp.getType().getElementType());
auto newOp = rewriter.create<PadOp>(
padTensorOp->getLoc(), newResultType, input, staticLow, staticHigh,
- padTensorOp.getLow(), padTensorOp.getHigh(), padTensorOp.getNofold(),
+ newLows, newLows, padTensorOp.getNofold(),
getPrunedAttributeList(padTensorOp, PadOp::getAttributeNames()));
IRMapping mapper;
diff --git a/mlir/test/Dialect/Tensor/canonicalize.mlir b/mlir/test/Dialect/Tensor/canonicalize.mlir
index ed964071358ac..0ee38410400f2 100644
--- a/mlir/test/Dialect/Tensor/canonicalize.mlir
+++ b/mlir/test/Dialect/Tensor/canonicalize.mlir
@@ -1361,7 +1361,7 @@ func.func @pad_same_static_shape(%arg0: tensor<5x6xf32>, %a: index)
// CHECK-LABEL: func @pad_fold_static(
// CHECK-SAME: %[[INPUT:.*]]: tensor<?x64x?x?xf32>) -> tensor<?x?x?x?xf32> {
// CHECK: %[[CST:.*]] = arith.constant 0.000000e+00 : f32
-// CHECK: %[[PADDING:.*]] = arith.constant 4 : index
+// CHECK-NOT: %[[PADDING:.*]] = arith.constant 4 : index
// CHECK: %[[PADDED:.*]] = tensor.pad %[[INPUT]]
// CHECK-SAME: low[0, 4, 1, 1] high[0, 4, 1, 1] {
// CHECK: ^bb0(%[[ARG1:.*]]: index, %[[ARG2:.*]]: index, %[[ARG3:.*]]: index, %[[ARG4:.*]]: index):
``````````
</details>
https://github.com/llvm/llvm-project/pull/79938
More information about the Mlir-commits
mailing list