[Mlir-commits] [mlir] [mlir][tensor] Make tensor::PadOp a ReifyRankedShapedTypeOpInterface and add a PadOp::FoldReifiedShape canonicalization (PR #145732)
Matthias Springer
llvmlistbot at llvm.org
Wed Jun 25 23:51:50 PDT 2025
================
@@ -3791,13 +3792,78 @@ struct FoldConsecutiveConstantPadding : public OpRewritePattern<tensor::PadOp> {
}
};
+struct FoldReifiedShape : public OpRewritePattern<tensor::PadOp> {
+ using OpRewritePattern<tensor::PadOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(tensor::PadOp padOp,
+ PatternRewriter &rewriter) const override {
+ if (padOp.getNofold()) {
+ return rewriter.notifyMatchFailure(padOp, "skipping unfoldable pad");
+ }
+
+ ReifiedRankedShapedTypeDims reifiedResultShapes;
+ if (failed(reifyResultShapes(rewriter, padOp, reifiedResultShapes)))
+ return failure();
----------------
matthias-springer wrote:
Yes, unfortunately `reifyResultShapes` cannot be used like that in a canonicalization pattern. You don't want the pattern to apply when the reified shape is the same. But in order to see the reified shape, you have generate IR first, at which point you can no longer abort.
https://github.com/llvm/llvm-project/pull/145732
More information about the Mlir-commits
mailing list