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

Adam Siemieniuk llvmlistbot at llvm.org
Mon Jun 23 01:48:03 PDT 2025


================
@@ -215,16 +216,33 @@ 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.
+
+  // Since some ops, like `linalg.map`, do not have block arguments for init
----------------
adam-smnk wrote:

> I can't actually reproduce the bug with builtin passes. I only discovered it when I applied my own control function for `populateElementwiseOpsFusionPatterns`

If there's a bug present is the current fuser, it'd be worth adding such test case to the `TestLinalgElementwiseFusion`. You could extend it with another option flag that adds necessary custom control logic.

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


More information about the Mlir-commits mailing list