Skip to content

Commit f3684d3

Browse files
VeeEMLukacma
authored andcommitted
[Flang] Generate math.sinh op for single and double precision sinh (llvm#162734)
Fixes issue with double precision sinh when using OpenMP offloading with AMD GPUs. The machinery to convert the op to a ROCDL call is already in place. llvm#162733
1 parent 07cff6c commit f3684d3

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,10 @@ static constexpr MathOperation mathOperations[] = {
17671767
genComplexMathOp<mlir::complex::SinOp>},
17681768
{"sin", RTNAME_STRING(CSinF128), FuncTypeComplex16Complex16,
17691769
genLibF128Call},
1770-
{"sinh", "sinhf", genFuncType<Ty::Real<4>, Ty::Real<4>>, genLibCall},
1771-
{"sinh", "sinh", genFuncType<Ty::Real<8>, Ty::Real<8>>, genLibCall},
1770+
{"sinh", "sinhf", genFuncType<Ty::Real<4>, Ty::Real<4>>,
1771+
genMathOp<mlir::math::SinhOp>},
1772+
{"sinh", "sinh", genFuncType<Ty::Real<8>, Ty::Real<8>>,
1773+
genMathOp<mlir::math::SinhOp>},
17721774
{"sinh", RTNAME_STRING(SinhF128), FuncTypeReal16Real16, genLibF128Call},
17731775
{"sinh", "csinhf", genFuncType<Ty::Complex<4>, Ty::Complex<4>>, genLibCall},
17741776
{"sinh", "csinh", genFuncType<Ty::Complex<8>, Ty::Complex<8>>, genLibCall},
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
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 = sinh(x)
1111
end function
1212

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

1618
function test_real8(x)
1719
real(8) :: x, test_real8
1820
test_real8 = sinh(x)
1921
end function
2022

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

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

flang/test/Lower/trigonometric-intrinsics.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ subroutine sinh_testcd(z)
278278
! CMPLX-PRECISE: fir.call @csin
279279

280280
! CHECK-LABEL: @fir.sinh.contract.f32.f32
281-
! CHECK: fir.call {{.*}}sinh
281+
! CHECK: math.sinh {{.*}} : f32
282282

283283
! CHECK-LABEL: @fir.sinh.contract.f64.f64
284-
! CHECK: fir.call {{.*}}sinh
284+
! CHECK: math.sinh {{.*}} : f64
285285

286286
! CHECK-LABEL: @fir.sinh.contract.z32.z32
287287
! CHECK: fir.call @csinhf

0 commit comments

Comments
 (0)