[Mlir-commits] [mlir] [mlir][linalg] Extend `FuseElementwiseOps` pattern to work with named ops (PR #144922)

Kunwar Grover llvmlistbot at llvm.org
Tue Nov 4 20:42:40 PST 2025


================
@@ -216,16 +217,17 @@ bool mlir::linalg::areElementwiseOpsFusable(OpOperand *fusedOperand) {
 /// Generate the region of the fused tensor operation. The region of the fused
 /// op must be empty.
 static void generateFusedElementwiseOpRegion(
-    RewriterBase &rewriter, GenericOp fusedOp,
+    RewriterBase &rewriter, LinalgOp fusedOp,
     AffineMap consumerToProducerLoopsMap, OpOperand *fusedOperand,
     unsigned nloops, llvm::SmallDenseSet<int> &preservedProducerResults) {
-  auto producer = cast<GenericOp>(fusedOperand->get().getDefiningOp());
-  auto consumer = cast<GenericOp>(fusedOperand->getOwner());
+  auto producer = cast<LinalgOp>(fusedOperand->get().getDefiningOp());
+  auto consumer = cast<LinalgOp>(fusedOperand->getOwner());
   // Build the region of the fused op.
+
   Block &producerBlock = producer->getRegion(0).front();
   Block &consumerBlock = consumer->getRegion(0).front();
----------------
Groverkss wrote:

You cannot do this on an interface. There is no gurantee that the op implementing this interface is carrying a region: https://github.com/llvm/llvm-project/blob/cdf52a1325e6329cef267ca93886481ddc5d554d/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td#L724

Today, the upstream named ops that are generated using a yaml file add a region and don't print it, but that is not the behavior of the interface. Anything querying a region on this interface is wrong.

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


More information about the Mlir-commits mailing list