[Mlir-commits] [mlir] [mlir] Add missing pad reshape propagation patterns (PR #168888)

Ian Wood llvmlistbot at llvm.org
Tue Nov 25 10:43:13 PST 2025


================
@@ -1921,6 +2024,59 @@ struct FoldReshapeWithGenericOpByCollapsing
   ControlFusionFn controlFoldingReshapes;
 };
 
+/// Computes the collapsed padding information for the given pad operation based
+/// on the provided collapsed shape and reassociation indices. Returns a
+/// PadDimInfo containing the low and high padding amounts and the collapsed
+/// shape for each dimension, or failure if the collapse is not possible.
+static FailureOr<PadDimInfo>
+computeCollapsedPadding(tensor::PadOp padOp,
+                        ArrayRef<ReassociationIndices> reassociations,
+                        PatternRewriter &rewriter) {
+  // If the padding value depends on the index values of the pad operation,
+  // then it may not be valid to collapse the dimensions, since it will change
+  // the index values on which the padding value depends.
+  if (!padOp.getConstantPaddingValue())
+    return failure();
----------------
IanWood1 wrote:

Same as above but for collapsing


https://github.com/llvm/llvm-project/blob/8f1bb92bbfa45d49103953dad0d0a5dcfd388959/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp#L1595-L1617

https://github.com/llvm/llvm-project/pull/168888


More information about the Mlir-commits mailing list