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

Adam Siemieniuk llvmlistbot at llvm.org
Mon Apr 27 05:52:20 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 &&
----------------
adam-smnk wrote:

> Is there a pass already to hoist invariant computations out of linalg.generic bodies?

I don't think so. Only more basic cases like `arith.add` on two compile-time constants get folded into a constant result that happens to be recreated outside on the linalg body.

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


More information about the Mlir-commits mailing list