[flang-commits] [flang] [Flang] Generate math.cosh op for non-precise cosh intrinsic calls (PR #122292)
Jan Leyonberg via flang-commits
flang-commits at lists.llvm.org
Thu Jan 9 07:09:37 PST 2025
https://github.com/jsjodin created https://github.com/llvm/llvm-project/pull/122292
This patch changes the codgegn for non-precise cosh calls to generate math.cosh ops. This wasn't done before because the math dialect did not have a cosh operation at the time.
>From 8a066120f16b5f24a6da5b1dafde9cc78a942468 Mon Sep 17 00:00:00 2001
From: Jan Leyonberg <jan_sjodin at yahoo.com>
Date: Wed, 8 Jan 2025 17:04:06 -0500
Subject: [PATCH] [Flang] Generate math.cosh op for non-precise cosh intrinsic
calls
This patch changes the codgegn for non-precise cosh calls to generate math.cosh
ops. This wasn't done before because the math dialect did not have a cosh
operation at the time.
---
flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 6 +++--
flang/test/Lower/math-lowering/cosh.f90 | 25 +++++++++++--------
flang/test/Lower/trigonometric-intrinsics.f90 | 4 +--
3 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 9a3777994a9df0..9d281ab8744a89 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1136,8 +1136,10 @@ static constexpr MathOperation mathOperations[] = {
genComplexMathOp<mlir::complex::CosOp>},
{"cos", RTNAME_STRING(CCosF128), FuncTypeComplex16Complex16,
genLibF128Call},
- {"cosh", "coshf", genFuncType<Ty::Real<4>, Ty::Real<4>>, genLibCall},
- {"cosh", "cosh", genFuncType<Ty::Real<8>, Ty::Real<8>>, genLibCall},
+ {"cosh", "coshf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
+ genMathOp<mlir::math::CoshOp>},
+ {"cosh", "cosh", genFuncType<Ty::Real<8>, Ty::Real<8>>,
+ genMathOp<mlir::math::CoshOp>},
{"cosh", RTNAME_STRING(CoshF128), FuncTypeReal16Real16, genLibF128Call},
{"cosh", "ccoshf", genFuncType<Ty::Complex<4>, Ty::Complex<4>>, genLibCall},
{"cosh", "ccosh", genFuncType<Ty::Complex<8>, Ty::Complex<8>>, genLibCall},
diff --git a/flang/test/Lower/math-lowering/cosh.f90 b/flang/test/Lower/math-lowering/cosh.f90
index 832448667a3860..8fc6e01e79da3c 100644
--- a/flang/test/Lower/math-lowering/cosh.f90
+++ b/flang/test/Lower/math-lowering/cosh.f90
@@ -1,9 +1,9 @@
-! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %s
-! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL %s
-! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %s
-! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL %s
-! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %s
-! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL %s
+! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %s
+! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL,FAST %s
+! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %s
+! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL,RELAXED %s
+! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %s
+! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL,PRECISE %s
function test_real4(x)
real :: x, test_real4
@@ -11,7 +11,10 @@ function test_real4(x)
end function
! ALL-LABEL: @_QPtest_real4
-! ALL: {{%[A-Za-z0-9._]+}} = fir.call @coshf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
+! FAST: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f32
+! RELAXED: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f32
+! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @coshf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
+
function test_real8(x)
real(8) :: x, test_real8
@@ -19,7 +22,9 @@ function test_real8(x)
end function
! ALL-LABEL: @_QPtest_real8
-! ALL: {{%[A-Za-z0-9._]+}} = fir.call @cosh({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
+! FAST: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f64
+! RELAXED: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f64
+! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @cosh({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
-! ALL-DAG: func.func private @coshf(f32) -> f32 attributes {fir.bindc_name = "coshf", fir.runtime}
-! ALL-DAG: func.func private @cosh(f64) -> f64 attributes {fir.bindc_name = "cosh", fir.runtime}
+! PRECISE-DAG: func.func private @coshf(f32) -> f32 attributes {fir.bindc_name = "coshf", fir.runtime}
+! PRECISE-DAG: func.func private @cosh(f64) -> f64 attributes {fir.bindc_name = "cosh", fir.runtime}
diff --git a/flang/test/Lower/trigonometric-intrinsics.f90 b/flang/test/Lower/trigonometric-intrinsics.f90
index 34cc59eaafd9b6..731ec6bbf68557 100644
--- a/flang/test/Lower/trigonometric-intrinsics.f90
+++ b/flang/test/Lower/trigonometric-intrinsics.f90
@@ -212,10 +212,10 @@ subroutine sinh_testcd(z)
! CMPLX-PRECISE: fir.call @ccos
! CHECK-LABEL: @fir.cosh.contract.f32.f32
-! CHECK: fir.call {{.*}}cosh
+! CHECK: math.cosh {{.*}} : f32
! CHECK-LABEL: @fir.cosh.contract.f64.f64
-! CHECK: fir.call {{.*}}cosh
+! CHECK: math.cosh {{.*}} : f64
! CHECK-LABEL: @fir.cosh.contract.z32.z32
! CHECK: fir.call @ccoshf
More information about the flang-commits
mailing list