Skip to content

Commit 15dba10

Browse files
committed
[mlir] Add math to LLVM lowering support for missing trigonometric & hyperbolic ops
1 parent 439de72 commit 15dba10

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ using CeilOpLowering = ConvertFMFMathToLLVMPattern<math::CeilOp, LLVM::FCeilOp>;
3939
using CopySignOpLowering =
4040
ConvertFMFMathToLLVMPattern<math::CopySignOp, LLVM::CopySignOp>;
4141
using CosOpLowering = ConvertFMFMathToLLVMPattern<math::CosOp, LLVM::CosOp>;
42+
using CoshOpLowering = ConvertFMFMathToLLVMPattern<math::CoshOp, LLVM::CoshOp>;
4243
using CtPopFOpLowering =
4344
VectorConvertToLLVMPattern<math::CtPopOp, LLVM::CtPopOp>;
4445
using Exp2OpLowering = ConvertFMFMathToLLVMPattern<math::Exp2Op, LLVM::Exp2Op>;
@@ -58,9 +59,12 @@ using RoundEvenOpLowering =
5859
using RoundOpLowering =
5960
ConvertFMFMathToLLVMPattern<math::RoundOp, LLVM::RoundOp>;
6061
using SinOpLowering = ConvertFMFMathToLLVMPattern<math::SinOp, LLVM::SinOp>;
62+
using SinhOpLowering = ConvertFMFMathToLLVMPattern<math::SinhOp, LLVM::SinhOp>;
6163
using SqrtOpLowering = ConvertFMFMathToLLVMPattern<math::SqrtOp, LLVM::SqrtOp>;
6264
using FTruncOpLowering =
6365
ConvertFMFMathToLLVMPattern<math::TruncOp, LLVM::FTruncOp>;
66+
using TanOpLowering = ConvertFMFMathToLLVMPattern<math::TanOp, LLVM::TanOp>;
67+
using TanhOpLowering = ConvertFMFMathToLLVMPattern<math::TanhOp, LLVM::TanhOp>;
6468

6569
// A `CtLz/CtTz/absi(a)` is converted into `CtLz/CtTz/absi(a, false)`.
6670
template <typename MathOp, typename LLVMOp>
@@ -310,6 +314,7 @@ void mlir::populateMathToLLVMConversionPatterns(
310314
CeilOpLowering,
311315
CopySignOpLowering,
312316
CosOpLowering,
317+
CoshOpLowering,
313318
CountLeadingZerosOpLowering,
314319
CountTrailingZerosOpLowering,
315320
CtPopFOpLowering,
@@ -327,8 +332,11 @@ void mlir::populateMathToLLVMConversionPatterns(
327332
RoundOpLowering,
328333
RsqrtOpLowering,
329334
SinOpLowering,
335+
SinhOpLowering,
330336
SqrtOpLowering,
331-
FTruncOpLowering
337+
FTruncOpLowering,
338+
TanOpLowering,
339+
TanhOpLowering
332340
>(converter);
333341
// clang-format on
334342
}

mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,33 @@ func.func @rsqrt(%arg0 : f32) {
161161

162162
// -----
163163

164-
// CHECK-LABEL: func @sine(
164+
// CHECK-LABEL: func @trigonometrics(
165165
// CHECK-SAME: f32
166-
func.func @sine(%arg0 : f32) {
166+
func.func @trigonometrics(%arg0 : f32) {
167167
// CHECK: llvm.intr.sin(%arg0) : (f32) -> f32
168168
%0 = math.sin %arg0 : f32
169+
170+
// CHECK: llvm.intr.cos(%arg0) : (f32) -> f32
171+
%1 = math.cos %arg0 : f32
172+
173+
// CHECK: llvm.intr.tan(%arg0) : (f32) -> f32
174+
%2 = math.tan %arg0 : f32
175+
func.return
176+
}
177+
178+
// -----
179+
180+
// CHECK-LABEL: func @hyperbolics(
181+
// CHECK-SAME: f32
182+
func.func @hyperbolics(%arg0 : f32) {
183+
// CHECK: llvm.intr.sinh(%arg0) : (f32) -> f32
184+
%0 = math.sinh %arg0 : f32
185+
186+
// CHECK: llvm.intr.cosh(%arg0) : (f32) -> f32
187+
%1 = math.cosh %arg0 : f32
188+
189+
// CHECK: llvm.intr.tanh(%arg0) : (f32) -> f32
190+
%2 = math.tanh %arg0 : f32
169191
func.return
170192
}
171193

0 commit comments

Comments
 (0)