[Mlir-commits] [mlir] [mlir][Linalg][Tensor] Preserve attrs on `tensor.pad` when lowering to dst-style (PR #182064)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Feb 19 09:05:17 PST 2026


================
@@ -96,39 +97,44 @@ static Operation *movePaddingToFillOrGenericOp(RewriterBase &rewriter,
   OpBuilder::InsertionGuard g(rewriter);
   RankedTensorType resultType = padOp.getResultType();
 
-  // Examine the yielded value to decide if a linalg.generic is neede or a
+  // Collect user/dialect attributes from the pad op to preserve on the newly
+  // created ops.
+  SmallVector<NamedAttribute> preservedAttrs =
+      getPrunedAttributeList(padOp, PadOp::getAttributeNames());
+
+  // Examine the yielded value to decide if a linalg.generic is needed or a
   // linalg.fill is sufficient.
   Value yieldedValue =
       cast<tensor::YieldOp>(padOp.getBody()->getTerminator()).getValue();
   Attribute constYieldedValue;
+  const bool isConstYieldedValue =
+      matchPattern(yieldedValue, m_Constant(&constYieldedValue));
   // Is the yielded value a bbArg defined outside of the PadOp?
-  bool outsideBbArg =
+  const bool isOutsideBbArg =
       isa<BlockArgument>(yieldedValue) &&
       cast<BlockArgument>(yieldedValue).getOwner()->getParentOp() !=
           padOp.getOperation();
   // Is the yielded value an OpResult defined outside of the PadOp?
-  bool outsideOpResult =
+  const bool isOutsideOpResult =
       isa<OpResult>(yieldedValue) &&
       yieldedValue.getDefiningOp()->getParentOp() != padOp.getOperation();
-  bool invariantYieldedValue = outsideBbArg || outsideOpResult;
-  if (matchPattern(yieldedValue, m_Constant(&constYieldedValue))) {
-    // Padding with a constant: Create linalg.fill.
-    Dialect *arithDialect =
-        rewriter.getContext()->getLoadedDialect<arith::ArithDialect>();
-    Value fillValue =
-        arithDialect
-            ->materializeConstant(rewriter, constYieldedValue,
-                                  yieldedValue.getType(), yieldedValue.getLoc())
-            ->getResult(0);
-    auto fillOp = linalg::FillOp::create(rewriter, loc, ValueRange(fillValue),
-                                         ValueRange(dest));
-    return fillOp;
-  }
-
-  if (invariantYieldedValue) {
-    // Padding with an invariant value.
+  const bool isInvariantYieldedValue =
----------------
MaheshRavishankar wrote:

I think these changes are a bit superfluous. Please drop them

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


More information about the Mlir-commits mailing list