[Mlir-commits] [mlir] [MLIR][Linalg] Specialize more binary elementwise ops (PR #192290)
Adam Siemieniuk
llvmlistbot at llvm.org
Mon Apr 27 03:56:08 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:
Can it handle more exotic generic like:
```mlir
#map = affine_map<(d0) -> (d0)>
func.func @entry(%A: tensor<?xi32>, %cst: i32, %Out: tensor<?xi32>
) -> tensor<?xi32> {
%c123_i32 = arith.constant 123 : i32
%0 = linalg.generic
{indexing_maps = [#map, #map], iterator_types = ["parallel"]}
ins(%A : tensor<?xi32>) outs(%Out : tensor<?xi32>) {
^bb0(%in: i32, %out: i32):
%v = arith.addi %c123_i32, %cst : i32
linalg.yield %v : i32
} -> tensor<?xi32>
return %0 : tensor<?xi32>
}
```
when the operand is unused?
There could still be other edge cases.
https://github.com/llvm/llvm-project/pull/192290
More information about the Mlir-commits
mailing list