[Mlir-commits] [mlir] [MLIR][IR] Add ConstantLikeInterface for extensible constant creation (PR #177740)
Ryan Kim
llvmlistbot at llvm.org
Sat Jan 24 05:44:54 PST 2026
https://github.com/chokobole updated https://github.com/llvm/llvm-project/pull/177740
>From ce50aa081c935103e22eff21ab9c7f160806f4f1 Mon Sep 17 00:00:00 2001
From: Ryan Kim <chokobole33 at gmail.com>
Date: Sat, 24 Jan 2026 22:43:24 +0900
Subject: [PATCH] [mlir][linalg] Use materializeConstant for dialect-agnostic
constant creation
Change scalar constant creation in ElementwiseOpFusion to use
the dialect's materializeConstant method instead of directly
creating arith::ConstantOp. This makes the fusion pattern work
correctly with constants from any dialect, not just arith.
Co-Authored-By: Claude Opus 4.5 <noreply at anthropic.com>
---
.../lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
index 72acd02d0d13d..ffc4a43123731 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
@@ -2307,8 +2307,12 @@ class FoldScalarOrSplatConstant : public OpRewritePattern<GenericOp> {
}
// Create a constant scalar value from the splat constant.
- Value scalarConstant =
- arith::ConstantOp::create(rewriter, def->getLoc(), constantAttr);
+ Operation *scalarConstantOp = def->getDialect()->materializeConstant(
+ rewriter, constantAttr, constantAttr.getType(), def->getLoc());
+ if (!scalarConstantOp)
+ return rewriter.notifyMatchFailure(
+ genericOp, "failed to materialize scalar constant");
+ Value scalarConstant = scalarConstantOp->getResult(0);
SmallVector<Value> outputOperands = genericOp.getOutputs();
auto fusedOp =
More information about the Mlir-commits
mailing list