Skip to content

Commit 2f7807e

Browse files
authored
[Flang] Generate math.cosh op for non-precise cosh intrinsic calls (#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.
1 parent d305fd0 commit 2f7807e

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,10 @@ static constexpr MathOperation mathOperations[] = {
11371137
genComplexMathOp<mlir::complex::CosOp>},
11381138
{"cos", RTNAME_STRING(CCosF128), FuncTypeComplex16Complex16,
11391139
genLibF128Call},
1140-
{"cosh", "coshf", genFuncType<Ty::Real<4>, Ty::Real<4>>, genLibCall},
1141-
{"cosh", "cosh", genFuncType<Ty::Real<8>, Ty::Real<8>>, genLibCall},
1140+
{"cosh", "coshf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
1141+
genMathOp<mlir::math::CoshOp>},
1142+
{"cosh", "cosh", genFuncType<Ty::Real<8>, Ty::Real<8>>,
1143+
genMathOp<mlir::math::CoshOp>},
11421144
{"cosh", RTNAME_STRING(CoshF128), FuncTypeReal16Real16, genLibF128Call},
11431145
{"cosh", "ccoshf", genFuncType<Ty::Complex<4>, Ty::Complex<4>>, genLibCall},
11441146
{"cosh", "ccosh", genFuncType<Ty::Complex<8>, Ty::Complex<8>>, genLibCall},
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %s
2-
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL %s
3-
! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %s
4-
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL %s
5-
! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %s
6-
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL %s
1+
! RUN: bbc -emit-fir %s -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %s
2+
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %s -o - | FileCheck --check-prefixes=ALL,FAST %s
3+
! RUN: bbc -emit-fir %s -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %s
4+
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %s -o - | FileCheck --check-prefixes=ALL,RELAXED %s
5+
! RUN: bbc -emit-fir %s -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %s
6+
! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %s -o - | FileCheck --check-prefixes=ALL,PRECISE %s
77

88
function test_real4(x)
99
real :: x, test_real4
1010
test_real4 = cosh(x)
1111
end function
1212

1313
! ALL-LABEL: @_QPtest_real4
14-
! ALL: {{%[A-Za-z0-9._]+}} = fir.call @coshf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
14+
! FAST: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f32
15+
! RELAXED: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f32
16+
! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @coshf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32
17+
1518

1619
function test_real8(x)
1720
real(8) :: x, test_real8
1821
test_real8 = cosh(x)
1922
end function
2023

2124
! ALL-LABEL: @_QPtest_real8
22-
! ALL: {{%[A-Za-z0-9._]+}} = fir.call @cosh({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
25+
! FAST: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f64
26+
! RELAXED: {{%[A-Za-z0-9._]+}} = math.cosh {{%[A-Za-z0-9._]+}} {{.*}}: f64
27+
! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @cosh({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64
2328

24-
! ALL-DAG: func.func private @coshf(f32) -> f32 attributes {fir.bindc_name = "coshf", fir.runtime}
25-
! ALL-DAG: func.func private @cosh(f64) -> f64 attributes {fir.bindc_name = "cosh", fir.runtime}
29+
! PRECISE-DAG: func.func private @coshf(f32) -> f32 attributes {fir.bindc_name = "coshf", fir.runtime}
30+
! PRECISE-DAG: func.func private @cosh(f64) -> f64 attributes {fir.bindc_name = "cosh", fir.runtime}

flang/test/Lower/trigonometric-intrinsics.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ subroutine sinh_testcd(z)
212212
! CMPLX-PRECISE: fir.call @ccos
213213

214214
! CHECK-LABEL: @fir.cosh.contract.f32.f32
215-
! CHECK: fir.call {{.*}}cosh
215+
! CHECK: math.cosh {{.*}} : f32
216216

217217
! CHECK-LABEL: @fir.cosh.contract.f64.f64
218-
! CHECK: fir.call {{.*}}cosh
218+
! CHECK: math.cosh {{.*}} : f64
219219

220220
! CHECK-LABEL: @fir.cosh.contract.z32.z32
221221
! CHECK: fir.call @ccoshf

0 commit comments

Comments
 (0)