-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Add math to LLVM lowering support for missing trigonometric & hyperbolic ops #125753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir] Add math to LLVM lowering support for missing trigonometric & hyperbolic ops #125753
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
db8b3ab
to
3baf642
Compare
@llvm/pr-subscribers-mlir Author: Paul Carabas (PaulCarabas) ChangesFull diff: https://github.com/llvm/llvm-project/pull/125753.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp b/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
index 668f8385ac2dcf4..98680773e00d2ac 100644
--- a/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
+++ b/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
@@ -39,6 +39,7 @@ using CeilOpLowering = ConvertFMFMathToLLVMPattern<math::CeilOp, LLVM::FCeilOp>;
using CopySignOpLowering =
ConvertFMFMathToLLVMPattern<math::CopySignOp, LLVM::CopySignOp>;
using CosOpLowering = ConvertFMFMathToLLVMPattern<math::CosOp, LLVM::CosOp>;
+using CoshOpLowering = ConvertFMFMathToLLVMPattern<math::CoshOp, LLVM::CoshOp>;
using CtPopFOpLowering =
VectorConvertToLLVMPattern<math::CtPopOp, LLVM::CtPopOp>;
using Exp2OpLowering = ConvertFMFMathToLLVMPattern<math::Exp2Op, LLVM::Exp2Op>;
@@ -58,9 +59,12 @@ using RoundEvenOpLowering =
using RoundOpLowering =
ConvertFMFMathToLLVMPattern<math::RoundOp, LLVM::RoundOp>;
using SinOpLowering = ConvertFMFMathToLLVMPattern<math::SinOp, LLVM::SinOp>;
+using SinhOpLowering = ConvertFMFMathToLLVMPattern<math::SinhOp, LLVM::SinhOp>;
using SqrtOpLowering = ConvertFMFMathToLLVMPattern<math::SqrtOp, LLVM::SqrtOp>;
using FTruncOpLowering =
ConvertFMFMathToLLVMPattern<math::TruncOp, LLVM::FTruncOp>;
+using TanOpLowering = ConvertFMFMathToLLVMPattern<math::TanOp, LLVM::TanOp>;
+using TanhOpLowering = ConvertFMFMathToLLVMPattern<math::TanhOp, LLVM::TanhOp>;
// A `CtLz/CtTz/absi(a)` is converted into `CtLz/CtTz/absi(a, false)`.
template <typename MathOp, typename LLVMOp>
@@ -310,6 +314,7 @@ void mlir::populateMathToLLVMConversionPatterns(
CeilOpLowering,
CopySignOpLowering,
CosOpLowering,
+ CoshOpLowering,
CountLeadingZerosOpLowering,
CountTrailingZerosOpLowering,
CtPopFOpLowering,
@@ -327,8 +332,11 @@ void mlir::populateMathToLLVMConversionPatterns(
RoundOpLowering,
RsqrtOpLowering,
SinOpLowering,
+ SinhOpLowering,
SqrtOpLowering,
- FTruncOpLowering
+ FTruncOpLowering,
+ TanOpLowering,
+ TanhOpLowering
>(converter);
// clang-format on
}
diff --git a/mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir b/mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
index 56129dbd2788923..24eef9341bf74f2 100644
--- a/mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
+++ b/mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
@@ -161,11 +161,33 @@ func.func @rsqrt(%arg0 : f32) {
// -----
-// CHECK-LABEL: func @sine(
+// CHECK-LABEL: func @trigonometrics(
// CHECK-SAME: f32
-func.func @sine(%arg0 : f32) {
+func.func @trigonometrics(%arg0 : f32) {
// CHECK: llvm.intr.sin(%arg0) : (f32) -> f32
%0 = math.sin %arg0 : f32
+
+ // CHECK: llvm.intr.cos(%arg0) : (f32) -> f32
+ %1 = math.cos %arg0 : f32
+
+ // CHECK: llvm.intr.tan(%arg0) : (f32) -> f32
+ %2 = math.tan %arg0 : f32
+ func.return
+}
+
+// -----
+
+// CHECK-LABEL: func @hyperbolics(
+// CHECK-SAME: f32
+func.func @hyperbolics(%arg0 : f32) {
+ // CHECK: llvm.intr.sinh(%arg0) : (f32) -> f32
+ %0 = math.sinh %arg0 : f32
+
+ // CHECK: llvm.intr.cosh(%arg0) : (f32) -> f32
+ %1 = math.cosh %arg0 : f32
+
+ // CHECK: llvm.intr.tanh(%arg0) : (f32) -> f32
+ %2 = math.tanh %arg0 : f32
func.return
}
|
3baf642
to
15dba10
Compare
@matthias-springer @tpopp @zero9178 could any of you please take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The build failure in flang seems to be real as they seem to have their own lowerings for math to LLVM. Can these be removed from flang now? IIRC the LLVM lowerings lower to libc calls if the target has no instruction for the intrinsic. |
Thanks @zero9178 for checking out the failure. |
8f7e6d7
to
c60f3c5
Compare
…hyperbolic ops Update flang test to reflect changes
c60f3c5
to
5ba25f2
Compare
I suspect this to be the right thing, but ideally one of the flang developers would be able to tell |
I think @vzakhari has done part of the Math work in flang. |
Hi @zero9178,
Where can I see the details of the failure? |
The build failures were with a previous revision of this PR that did not yet incorporate the test changes in the current version. |
It should be okay to convert The build failure that you refer to, is it about the actual compiler build or about flang LIT tests? |
I think this was LIT tests failures. |
Thanks, Valentin! I suppose |
Yes, it was just the LIT test which was failing ( Thanks all for your input! The PR checks are fully green now - if everything's fine, can anybody help with the merge, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge it. Thank you for the changes!
@PaulCarabas Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…hyperbolic ops (llvm#125753) The patch adds support for math -> LLVM dialect lowering for TanOp, Sinh, Cosh, Tanh
The patch adds support for math -> LLVM dialect lowering for TanOp, Sinh, Cosh, Tanh