diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 6a343645ab878..4e5fa4f86371a 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -1023,8 +1023,10 @@ static constexpr MathOperation mathOperations[] = { {"abs", "cabs", genFuncType, Ty::Complex<8>>, genComplexMathOp}, {"abs", RTNAME_STRING(CAbsF128), FuncTypeReal16Complex16, genLibF128Call}, - {"acos", "acosf", genFuncType, Ty::Real<4>>, genLibCall}, - {"acos", "acos", genFuncType, Ty::Real<8>>, genLibCall}, + {"acos", "acosf", genFuncType, Ty::Real<4>>, + genMathOp}, + {"acos", "acos", genFuncType, Ty::Real<8>>, + genMathOp}, {"acos", RTNAME_STRING(AcosF128), FuncTypeReal16Real16, genLibF128Call}, {"acos", "cacosf", genFuncType, Ty::Complex<4>>, genLibCall}, {"acos", "cacos", genFuncType, Ty::Complex<8>>, genLibCall}, diff --git a/flang/test/Lower/HLFIR/elemental-intrinsics.f90 b/flang/test/Lower/HLFIR/elemental-intrinsics.f90 index dd79688663cba..689f0a08ca7ab 100644 --- a/flang/test/Lower/HLFIR/elemental-intrinsics.f90 +++ b/flang/test/Lower/HLFIR/elemental-intrinsics.f90 @@ -15,7 +15,7 @@ subroutine simple_elemental(x,y) ! CHECK: ^bb0(%[[VAL_9:.*]]: index): ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_9]]) : (!fir.ref>, index) -> !fir.ref ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_10]] : !fir.ref -! CHECK: %[[VAL_12:.*]] = fir.call @acosf(%[[VAL_11]]) fastmath : (f32) -> f32 +! CHECK: %[[VAL_12:.*]] = math.acos %[[VAL_11]] fastmath : f32 ! CHECK: hlfir.yield_element %[[VAL_12]] : f32 ! CHECK: } ! CHECK: hlfir.assign diff --git a/flang/test/Lower/Intrinsics/acos.f90 b/flang/test/Lower/Intrinsics/acos.f90 index d2ef8e1cef0a8..849d36ad1323b 100644 --- a/flang/test/Lower/Intrinsics/acos.f90 +++ b/flang/test/Lower/Intrinsics/acos.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,15 +11,9 @@ function test_real4(x) end function ! ALL-LABEL: @_QPtest_real4 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @acosf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = acos(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @acos({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64 +! FAST: {{%[A-Za-z0-9._]+}} = math.acos {{%[A-Za-z0-9._]+}} {{.*}}: f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.acos {{%[A-Za-z0-9._]+}} {{.*}}: f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @acosf({{%[A-Za-z0-9._]+}}) {{.*}}: (f32) -> f32 function test_complex4(x) complex :: x, test_complex4 @@ -37,3 +31,15 @@ function test_complex8(x) ! ALL-LABEL: @_QPtest_complex8 ! ALL: {{%[A-Za-z0-9._]+}} = fir.call @cacos({{%[A-Za-z0-9._]+}}) {{.*}}: (complex) -> complex +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = acos(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.acos {{%[A-Za-z0-9._]+}} {{.*}}: f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.acos {{%[A-Za-z0-9._]+}} {{.*}}: f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @acos({{%[A-Za-z0-9._]+}}) {{.*}}: (f64) -> f64 + +! PRECISE-DAG: func.func private @acosf(f32) -> f32 attributes {fir.bindc_name = "acosf", fir.runtime} +! PRECISE-DAG: func.func private @acos(f64) -> f64 attributes {fir.bindc_name = "acos", fir.runtime} diff --git a/flang/test/Lower/dummy-procedure.f90 b/flang/test/Lower/dummy-procedure.f90 index 6874e8eca90b9..a84c351b1166b 100644 --- a/flang/test/Lower/dummy-procedure.f90 +++ b/flang/test/Lower/dummy-procedure.f90 @@ -154,7 +154,7 @@ subroutine todo3(dummy_proc) ! CHECK-LABEL: func private @fir.acos.f32.ref_f32(%arg0: !fir.ref) -> f32 !CHECK: %[[load:.*]] = fir.load %arg0 - !CHECK: %[[res:.*]] = fir.call @acosf(%[[load]]) fastmath : (f32) -> f32 + !CHECK: %[[res:.*]] = math.acos %[[load]] fastmath : f32 !CHECK: return %[[res]] : f32 ! CHECK-LABEL: func private @fir.atan2.f32.ref_f32.ref_f32( diff --git a/flang/test/Lower/trigonometric-intrinsics.f90 b/flang/test/Lower/trigonometric-intrinsics.f90 index 731ec6bbf6855..d1edd4ef48dc3 100644 --- a/flang/test/Lower/trigonometric-intrinsics.f90 +++ b/flang/test/Lower/trigonometric-intrinsics.f90 @@ -87,6 +87,34 @@ subroutine cos_testcd(z) z = cos(z) end subroutine +! CHECK-LABEL: acos_testr +subroutine acos_testr(a, b) + real :: a, b +! CHECK: fir.call @fir.acos.contract.f32.f32 + b = acos(a) +end subroutine + +! CHECK-LABEL: acos_testd +subroutine acos_testd(a, b) + real(kind=8) :: a, b +! CHECK: fir.call @fir.acos.contract.f64.f64 + b = acos(a) +end subroutine + +! CHECK-LABEL: acos_testc +subroutine acos_testc(z) + complex :: z +! CHECK: fir.call @fir.acos.contract.z32.z32 + z = acos(z) +end subroutine + +! CHECK-LABEL: acos_testcd +subroutine acos_testcd(z) + complex(kind=8) :: z +! CHECK: fir.call @fir.acos.contract.z64.z64 + z = acos(z) +end subroutine + ! CHECK-LABEL: cosh_testr subroutine cosh_testr(a, b) real :: a, b @@ -211,6 +239,18 @@ subroutine sinh_testcd(z) ! CMPLX-FAST: complex.cos %{{.*}} : complex ! CMPLX-PRECISE: fir.call @ccos +! CHECK-LABEL: @fir.acos.contract.f32.f32 +! CHECK: math.acos {{.*}} : f32 + +! CHECK-LABEL: @fir.acos.contract.f64.f64 +! CHECK: math.acos {{.*}} : f64 + +! CHECK-LABEL: @fir.acos.contract.z32.z32 +! CHECK: fir.call @cacosf + +! CHECK-LABEL: @fir.acos.contract.z64.z64 +! CHECK: fir.call @cacos + ! CHECK-LABEL: @fir.cosh.contract.f32.f32 ! CHECK: math.cosh {{.*}} : f32