diff --git a/mlir/include/mlir/Dialect/Math/IR/MathOps.td b/mlir/include/mlir/Dialect/Math/IR/MathOps.td --- a/mlir/include/mlir/Dialect/Math/IR/MathOps.td +++ b/mlir/include/mlir/Dialect/Math/IR/MathOps.td @@ -244,6 +244,40 @@ }]; } +//===----------------------------------------------------------------------===// +// ExpM1Op +//===----------------------------------------------------------------------===// + +def ExpM1Op : FloatUnaryOp<"expm1"> { + let summary = "base-e exponential of the specified value minus 1"; + let description = [{ + Syntax: + + ``` + operation ::= ssa-id `=` `math.expm1` ssa-use `:` type + ``` + + expm1(x) := exp(x) - 1 + + The `expm1` operation takes one operand and returns one result of the same + type. This type may be a float scalar type, a vector whose element type is + float, or a tensor of floats. It has no standard attributes. + + Example: + + ```mlir + // Scalar natural exponential minus 1. + %a = math.expm1 %b : f64 + + // SIMD vector element-wise natural exponential minus 1. + %f = math.expm1 %g : vector<4xf32> + + // Tensor element-wise natural exponential minus 1. + %x = math.expm1 %y : tensor<4x?xf8> + ``` + }]; +} + //===----------------------------------------------------------------------===// // LogOp //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Math/ops.mlir b/mlir/test/Dialect/Math/ops.mlir --- a/mlir/test/Dialect/Math/ops.mlir +++ b/mlir/test/Dialect/Math/ops.mlir @@ -74,6 +74,18 @@ return } +// CHECK-LABEL: func @expm1( +// CHECK-SAME: %[[F:.*]]: f32, %[[V:.*]]: vector<4xf32>, %[[T:.*]]: tensor<4x4x?xf32>) +func @expm1(%f: f32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) { + // CHECK: %{{.*}} = math.expm1 %[[F]] : f32 + %0 = math.expm1 %f : f32 + // CHECK: %{{.*}} = math.expm1 %[[V]] : vector<4xf32> + %1 = math.expm1 %v : vector<4xf32> + // CHECK: %{{.*}} = math.expm1 %[[T]] : tensor<4x4x?xf32> + %2 = math.expm1 %t : tensor<4x4x?xf32> + return +} + // CHECK-LABEL: func @log( // CHECK-SAME: %[[F:.*]]: f32, %[[V:.*]]: vector<4xf32>, %[[T:.*]]: tensor<4x4x?xf32>) func @log(%f: f32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) {