[Mlir-commits] [mlir] [MLIR][Linalg] Remove unary named ops (PR #220905)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 3 05:26:57 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-linalg

Author: Renato Golin (rengolin)

<details>
<summary>Changes</summary>

Remove ops, change tests to elementwise to continue working as is.

Ref:
https://discourse.llvm.org/t/rfc-update-semantics-of-linalg-named-operations-unary-binary-ternary/91531

---

Patch is 162.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/220905.diff


29 Files Affected:

- (modified) mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h (+1-1) 
- (modified) mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml (+1-456) 
- (modified) mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp (+2-2) 
- (modified) mlir/lib/Dialect/Linalg/Transforms/CategoryToNamedOp.cpp (+2-28) 
- (modified) mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp (+1-27) 
- (modified) mlir/lib/Dialect/Linalg/Transforms/Specialize.cpp (+40-38) 
- (modified) mlir/python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py (+1-157) 
- (modified) mlir/test/Dialect/Bufferization/canonicalize.mlir (+2-2) 
- (modified) mlir/test/Dialect/Linalg/elementwise/named-to-elementwise.mlir (-13) 
- (modified) mlir/test/Dialect/Linalg/generalize-named-ops.mlir (-275) 
- (removed) mlir/test/Dialect/Linalg/linalg-morph-category-ops.mlir (-15) 
- (modified) mlir/test/Dialect/Linalg/linalg-morph-elementwise-to-named.mlir (+3-78) 
- (modified) mlir/test/Dialect/Linalg/linalg-morph-multi-step.mlir (-51) 
- (modified) mlir/test/Dialect/Linalg/match-ops-interpreter.mlir (+3-3) 
- (modified) mlir/test/Dialect/Linalg/named-ops-fail.mlir (-208) 
- (modified) mlir/test/Dialect/Linalg/named-ops.mlir (-403) 
- (modified) mlir/test/Dialect/Linalg/roundtrip-morphism-linalg-category-ops.mlir (-6) 
- (modified) mlir/test/Dialect/Linalg/roundtrip-morphism-linalg-named-ops.mlir (-62) 
- (modified) mlir/test/Dialect/Linalg/scalable-unpack-producer-fusion.mlir (+15-15) 
- (modified) mlir/test/Dialect/Linalg/specialize-generic-ops.mlir (+9-88) 
- (modified) mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir (+18-18) 
- (modified) mlir/test/Dialect/Linalg/transform-op-fuse.mlir (+63-63) 
- (modified) mlir/test/Dialect/Linalg/transform-op-generalize.mlir (+2-2) 
- (removed) mlir/test/Dialect/Linalg/transform-op-specialize-elemwise-unary.mlir (-122) 
- (modified) mlir/test/Dialect/SCF/canonicalize.mlir (+4-4) 
- (modified) mlir/test/Dialect/SCF/parallel-loop-unroll.mlir (+6-6) 
- (modified) mlir/test/Interfaces/TilingInterface/tile-and-fuse-consumer-using-slices.mlir (+10-10) 
- (modified) mlir/test/Interfaces/TilingInterface/tile-and-fuse-consumer.mlir (+11-11) 
- (modified) mlir/test/python/dialects/linalg/opdsl/test_core_named_ops.py (+1-2) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h
index 9ff32216ce042..682d016849e88 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h
@@ -147,7 +147,7 @@ std::optional<SmallVector<int64_t>>
 isaTransposeOpInterface(GenericOp genericOp);
 
 /// Checks whether a given `genericOp` is semantically equivalent to a single
-/// linalg elementwise unary op, e.g. `linalg.exp` or
+/// linalg elementwise unary op, e.g.
 /// `linalg.elementwise kind=#linalg.elementwise_kind<exp>`.
 /// If `allowNonIdentityMaps` is true, operations with custom indexing maps are
 /// included in the check. Note that these operations can only be represented by
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
index 521afc991063f..5514ba3afcf37 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.yaml
@@ -44,461 +44,6 @@ structured_op: !LinalgStructuredOpConfig
         - !ScalarExpression
           scalar_arg: I
 --- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: exp
-  cpp_class_name: ExpOp
-  doc: |-
-    Applies exp(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: exp
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: log
-  cpp_class_name: LogOp
-  doc: |-
-    Applies log(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: log
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: abs
-  cpp_class_name: AbsOp
-  doc: |-
-    Applies abs(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: abs
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: ceil
-  cpp_class_name: CeilOp
-  doc: |-
-    Applies ceil(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: ceil
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: floor
-  cpp_class_name: FloorOp
-  doc: |-
-    Applies floor(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: floor
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: negf
-  cpp_class_name: NegFOp
-  doc: |-
-    Applies negf(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: negf
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: reciprocal
-  cpp_class_name: ReciprocalOp
-  doc: |-
-    Applies reciprocal(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: reciprocal
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: round
-  cpp_class_name: RoundOp
-  doc: |-
-    Applies round(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: round
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: sqrt
-  cpp_class_name: SqrtOp
-  doc: |-
-    Applies sqrt(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: sqrt
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: rsqrt
-  cpp_class_name: RsqrtOp
-  doc: |-
-    Applies rsqrt(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: rsqrt
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: square
-  cpp_class_name: SquareOp
-  doc: |-
-    Applies square(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: square
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: tanh
-  cpp_class_name: TanhOp
-  doc: |-
-    Applies tanh(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: tanh
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
-metadata: !LinalgOpMetadata
-  name: erf
-  cpp_class_name: ErfOp
-  doc: |-
-    Applies erf(x) elementwise.
-
-    No numeric casting is performed on the input operand.
-structured_op: !LinalgStructuredOpConfig
-  args:
-  - !LinalgOperandDefConfig
-    name: I
-    kind: input_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  - !LinalgOperandDefConfig
-    name: O
-    kind: output_tensor
-    type_var: T1
-    shape_map: affine_map<() -> ()>
-  indexing_maps: !LinalgIndexingMapsConfig
-    static_indexing_maps:
-    - affine_map<() -> ()>
-    - affine_map<() -> ()>
-  iterator_types: []
-  assignments:
-  - !ScalarAssign
-    arg: O
-    value: !ScalarExpression
-      scalar_fn:
-        kind: unary
-        fn_name: erf
-        operands:
-        - !ScalarExpression
-          scalar_arg: I
---- !LinalgOpConfig
 metadata: !LinalgOpMetadata
   name: add
   cpp_class_name: AddOp
@@ -847,7 +392,7 @@ metadata: !LinalgOpMetadata
   name: powf
   cpp_class_name: PowFOp
   doc: |-
-    Takes the powf(lhs, rhs) between two inputs, elementwise. For powf(arg, 2) use `linalg.square`.
+    Takes the powf(lhs, rhs) between two inputs, elementwise. For powf(arg, 2) use `linalg.elementwise kind=square`.
 
     Only applies to floating point values.
 
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index 3045e65630cf2..cff613f389669 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -256,8 +256,8 @@ isaElemwiseSingleUnaryOrBinaryOpInterface(linalg::GenericOp op, unsigned arity,
 
   // The payload op must have one result and at least arity-many operands
   // (otherwise not all inputs can be used). It can have additional operands
-  // from outside of the generic op (e.g. div(1, x) for linalg.reciprocal) or
-  // use an input more than once (e.g. mul(x, x) for linalg.square).
+  // from outside of the generic op (e.g. div(1, x) for elementwise reciprocal)
+  // or use an input more than once (e.g. mul(x, x) for elementwise square).
   Operation *oper = &body->front();
   if (oper->getNumOperands() < arity || oper->getNumResults() != 1)
     return false;
diff --git a/mlir/lib/Dialect/Linalg/Transforms/CategoryToNamedOp.cpp b/mlir/lib/Dialect/Linalg/Transforms/CategoryToNamedOp.cpp
index 6d1f61100dbf5..711069caff7c4 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/CategoryToNamedOp.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/CategoryToNamedOp.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 //
 // This file implements rewriting of linalg category ops (e.g.
-// `linalg.elementwise`) to their equivalent named ops (e.g. `linalg.add`,
-// `linalg.exp`). This is the reverse of NamedToElementwise.cpp.
+// `linalg.elementwise`) to their equivalent named ops (e.g. `linalg.add`).
+// This is the reverse of NamedToElementwise.cpp.
 //
 //===----------------------------------------------------------------------===//
 
@@ -46,32 +46,6 @@ struct ElementwiseToNamedPattern : public OpRewritePattern<ElementwiseOp> {
     };
 
     switch (op.getKind()) {
-    case ElementwiseKind::exp:
-      return replaceWith(ExpOp{});
-    case ElementwiseKind::log:
-      return replaceWith(LogOp{});
-    case ElementwiseKind::abs:
-      return replaceWith(AbsOp{});
-    case ElementwiseKind::ceil:
-      return replaceWith(CeilOp{});
-    case ElementwiseKind::floor:
-      return replaceWith(FloorOp{});
-    case ElementwiseKind::negf:
-      return replaceWith(NegFOp{});
-    case ElementwiseKind::reciprocal:
-      return replaceWith(ReciprocalOp{});
-    case ElementwiseKind::round:
-      return replaceWith(RoundOp{});
-    case ElementwiseKind::sqrt:
-      return replaceWith(SqrtOp{});
-    case ElementwiseKind::rsqrt:
-      return replaceWith(RsqrtOp{});
-    case ElementwiseKind::square:
-      return replaceWith(SquareOp{});
-    case ElementwiseKind::tanh:
-      return replaceWith(TanhOp{});
-    case ElementwiseKind::erf:
-      return replaceWith(ErfOp{});
     case ElementwiseKind::add:
       return replaceWith(AddOp{});
     case ElementwiseKind::sub:
diff --git a/mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp b/mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp
index c9045566473cb..b2687cb4dc87b 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/NamedToElementwise.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // This file implements rewriting those linalg named ops that are essentially
-// elementwise e.g. `linalg.exp`, to `linalg.elementwise`. This allows further
+// elementwise e.g. `linalg.add`, to `linalg.elementwise`. This allows further
 // optimization on `linalg.elementwise` such as folding transpose, broadcast.
 //
 //===----------------------------------------------------------------------===//
@@ -35,19 +35,6 @@ ElementwiseKind getKind(Operation *op) {
       .Case([](DivOp) { return ElementwiseKind::div; })
       .Case([](DivUnsignedOp) { return ElementwiseKind::div_unsigned; })
       .Case([](PowFOp) { return ElementwiseKind::powf; })
-      .Case([](ExpOp) { return ElementwiseKind::exp; })
-      .Case([](LogOp) { return ElementwiseKind::log; })
-      .Case([](AbsOp) { return ElementwiseKind::abs; })
-      .Case([](CeilOp) { return ElementwiseKind::ceil; })
-      .Case([](FloorOp) { return ElementwiseKind::floor; })
-      .Case([](NegFOp) { return ElementwiseKind::negf; })
-      .Case([](ReciprocalOp) { return ElementwiseKind::reciprocal; })
-      .Case([](RoundOp) { return ElementwiseKind::round; })
-      .Case([](SqrtOp) { return ElementwiseKind::sqrt; })
-      .Case([](RsqrtOp) { return ElementwiseKind::rsqrt; })
-      .Case([](SquareOp) { return ElementwiseKind::square; })
-      .Case([](TanhOp) { return ElementwiseKind::tanh; })
-      .Case([](ErfOp) { return ElementwiseKind::erf; })
       .DefaultUnreachable("unhandled case in named to elementwise");
 }
 
@@ -79,17 +66,4 @@ void mlir::linalg::populateLinalgNamedToElementwisePatterns(
   patterns.add<NamedToElementwisePattern<DivOp>>(patterns.getContext());
   patterns.add<NamedToElementwisePattern<DivUnsignedOp>>(patterns.getContext());
   patterns.add<NamedToElementwisePattern<PowFOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<ExpOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<LogOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<AbsOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<CeilOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<FloorOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<NegFOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<ReciprocalOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<RoundOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<SqrtOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<RsqrtOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<SquareOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<TanhOp>>(patterns.getContext());
-  patterns.add<NamedToElementwisePattern<ErfOp>>(patterns.getContext());
 }
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Specialize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Specialize.cpp
index 1bdcd0be31329..a063465e1a4c9 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Specialize.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Specialize.cpp
@@ -104,11 +104,12 @@ static bool findIndexOfScalarOperand(GenericOp genericOp, int &index) {
 //       linalg.yield %1 : f32
 //     } -> tensor<?x?xf32>
 //
-// is specialized to either
-//   linalg.exp ins(...) outs(...) -> ...
-// or
+// is specialized to
 //   linalg.elementwise kind=#linalg.elementwise_kind<exp> ...
 //
+// A named op is emitted instead for binary/ternary ops that still have a
+// linalg.* named equivalent (e.g. linalg.add).
+//
 // Only the category op can carry non-identity indexing maps; these are
 // transferred verbatim from the `genericOp`.
 //
@@ -191,42 +192,41 @@ static FailureOr<LinalgOp> specializeLinalgElementwise(RewriterBase &rewriter,
   };
 
   if (isUnary) {
-    if (isa<math::ExpOp>(op))
-      return replaceOp(ExpOp{}, ElementwiseKind::exp);
-    if (isa<math::LogOp>(op))
-      return replaceOp(LogOp{}, ElementwiseKind::log);
-    if (isa<math::AbsFOp>(op))
-      return replaceOp(AbsOp{}, ElementwiseKind::abs);
-    if (isa<math::CeilOp>(op))
-      return replaceOp(CeilOp{}, ElementwiseKind::ceil);
-    if (isa<math::FloorOp>(op))
-      return replaceOp(FloorOp{}, ElementwiseKind::floor);
-    if (isa<arith::NegFOp>(op))
-      return replaceOp(NegFOp{}, ElementwiseKind::negf);
-    if (auto divOp = dyn_cast<arith::DivFOp>(...
[truncated]

``````````

</details>


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


More information about the Mlir-commits mailing list