[Mlir-commits] [mlir] [MLIR][Linalg] Specialize more binary elementwise ops (PR #192290)

Julian Oppermann llvmlistbot at llvm.org
Mon Apr 27 05:24:31 PDT 2026


================
@@ -100,62 +131,142 @@ specializeLinalgUnaryElementwise(RewriterBase &rewriter, GenericOp genericOp,
         genericOp,
         "non-identity indexing maps prevent specialization to named op");
 
+  // Classify the generic op.
+  bool isUnary = genericOp.getNumDpsInputs() == 1;
+  bool isBinary = genericOp.getNumDpsInputs() == 2;
+
+  // Will inspect the body operation to determine named op or elementwise kind.
+  Operation *op = &genericOp.getBody()->front();
+
+  // Detect variations from canonical forms.
+  bool hasSwappedOperands = isBinary && areBinOpsSwapped(genericOp);
+  int scalarOprIdx = -1;
+  bool hasScalarOperand = isUnary && op->getNumOperands() == 2 &&
----------------
jopperm wrote:

Interesting example!
- The new matchers in this PR wouldn't touch it because it doesn't conform to [`isaElemwiseSingleUnaryOpInterface`](https://github.com/jopperm/llvm-project/blob/825ef6c0de39dc8fa2868538f40e34fce50bb49d/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp#L277), which checks that all inputs are used in the payload.
- Is there a pass already to hoist invariant computations out of `linalg.generic` bodies? If not, I think that would be super useful as a preparation; then your example should ultimately morph to `linalg.fill`.

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


More information about the Mlir-commits mailing list