diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp index 0afbb7b1c6fa1..fa405c29516f8 100644 --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -1019,6 +1019,8 @@ static constexpr RuntimeFunction llvmIntrinsics[] = { // ceil is used for CEILING but is different, it returns a real. {"ceil", "llvm.ceil.f32", genF32F32FuncType}, {"ceil", "llvm.ceil.f64", genF64F64FuncType}, + {"cos", "llvm.cos.f32", genF32F32FuncType}, + {"cos", "llvm.cos.f64", genF64F64FuncType}, {"cosh", "coshf", genF32F32FuncType}, {"cosh", "cosh", genF64F64FuncType}, {"exp", "llvm.exp.f32", genF32F32FuncType}, @@ -1040,6 +1042,8 @@ static constexpr RuntimeFunction llvmIntrinsics[] = { {"sign", "llvm.copysign.f64", genF64F64F64FuncType}, {"sign", "llvm.copysign.f80", genF80F80F80FuncType}, {"sign", "llvm.copysign.f128", genF128F128F128FuncType}, + {"sin", "llvm.sin.f32", genF32F32FuncType}, + {"sin", "llvm.sin.f64", genF64F64FuncType}, {"sinh", "sinhf", genF32F32FuncType}, {"sinh", "sinh", genF64F64FuncType}, {"sqrt", "llvm.sqrt.f32", genF32F32FuncType}, diff --git a/flang/test/Lower/llvm-math.f90 b/flang/test/Lower/llvm-math.f90 index aab0b2b1f079d..f346642830522 100644 --- a/flang/test/Lower/llvm-math.f90 +++ b/flang/test/Lower/llvm-math.f90 @@ -175,4 +175,44 @@ SUBROUTINE SQRTD_WRAPPER(IN, OUT) ! CHECK-LABEL: func private @fir.sqrt.f64.f64(%arg0: f64) ! CHECK-NEXT: %0 = fir.call @llvm.sqrt.f64(%arg0) : (f64) -> f64 ! CHECK-NEXT: return %0 : f64 +! CHECK-NEXT: } + + SUBROUTINE COS_WRAPPER(IN, OUT) + REAL :: IN, OUT + OUT = COS(IN) + END SUBROUTINE + +! CHECK-LABEL: func private @fir.cos.f32.f32(%arg0: f32) +! CHECK-NEXT: %0 = fir.call @llvm.cos.f32(%arg0) : (f32) -> f32 +! CHECK-NEXT: return %0 : f32 +! CHECK-NEXT: } + + SUBROUTINE COSD_WRAPPER(IN, OUT) + REAL(KIND=8) :: IN, OUT + OUT = COS(IN) + END SUBROUTINE + +! CHECK-LABEL: func private @fir.cos.f64.f64(%arg0: f64) +! CHECK-NEXT: %0 = fir.call @llvm.cos.f64(%arg0) : (f64) -> f64 +! CHECK-NEXT: return %0 : f64 +! CHECK-NEXT: } + + SUBROUTINE SIN_WRAPPER(IN, OUT) + REAL :: IN, OUT + OUT = SIN(IN) + END SUBROUTINE + +! CHECK-LABEL: func private @fir.sin.f32.f32(%arg0: f32) +! CHECK-NEXT: %0 = fir.call @llvm.sin.f32(%arg0) : (f32) -> f32 +! CHECK-NEXT: return %0 : f32 +! CHECK-NEXT: } + + SUBROUTINE SIND_WRAPPER(IN, OUT) + REAL(KIND=8) :: IN, OUT + OUT = SIN(IN) + END SUBROUTINE + +! CHECK-LABEL: func private @fir.sin.f64.f64(%arg0: f64) +! CHECK-NEXT: %0 = fir.call @llvm.sin.f64(%arg0) : (f64) -> f64 +! CHECK-NEXT: return %0 : f64 ! CHECK-NEXT: } diff --git a/flang/test/Lower/trigonometric-intrinsics.f90 b/flang/test/Lower/trigonometric-intrinsics.f90 index 8ec8f135cb7d8..51d6e149df45c 100644 --- a/flang/test/Lower/trigonometric-intrinsics.f90 +++ b/flang/test/Lower/trigonometric-intrinsics.f90 @@ -29,6 +29,34 @@ subroutine atan_testcd(z) z = atan(z) end subroutine +! CHECK-LABEL: cos_testr +subroutine cos_testr(a, b) + real :: a, b +! CHECK: fir.call @fir.cos.f32.f32 + b = cos(a) +end subroutine + +! CHECK-LABEL: cos_testd +subroutine cos_testd(a, b) + real(kind=8) :: a, b +! CHECK: fir.call @fir.cos.f64.f64 + b = cos(a) +end subroutine + +! CHECK-LABEL: cos_testc +subroutine cos_testc(z) + complex :: z +! CHECK: fir.call @fir.cos.z4.z4 + z = cos(z) +end subroutine + +! CHECK-LABEL: cos_testcd +subroutine cos_testcd(z) + complex(kind=8) :: z +! CHECK: fir.call @fir.cos.z8.z8 + z = cos(z) +end subroutine + ! CHECK-LABEL: cosh_testr subroutine cosh_testr(a, b) real :: a, b @@ -57,6 +85,34 @@ subroutine cosh_testcd(z) z = cosh(z) end subroutine +! CHECK-LABEL: sin_testr +subroutine sin_testr(a, b) + real :: a, b +! CHECK: fir.call @fir.sin.f32.f32 + b = sin(a) +end subroutine + +! CHECK-LABEL: sin_testd +subroutine sin_testd(a, b) + real(kind=8) :: a, b +! CHECK: fir.call @fir.sin.f64.f64 + b = sin(a) +end subroutine + +! CHECK-LABEL: sin_testc +subroutine sin_testc(z) + complex :: z +! CHECK: fir.call @fir.sin.z4.z4 + z = sin(z) +end subroutine + +! CHECK-LABEL: sin_testcd +subroutine sin_testcd(z) + complex(kind=8) :: z +! CHECK: fir.call @fir.sin.z8.z8 + z = sin(z) +end subroutine + ! CHECK-LABEL: sinh_testr subroutine sinh_testr(a, b) real :: a, b @@ -97,6 +153,18 @@ subroutine sinh_testcd(z) ! CHECK-LABEL: @fir.atan.z8.z8 ! CHECK: fir.call {{.*}}atan +! CHECK-LABEL: @fir.cos.f32.f32 +! CHECK: fir.call {{.*}}cos + +! CHECK-LABEL: @fir.cos.f64.f64 +! CHECK: fir.call {{.*}}cos + +! CHECK-LABEL: @fir.cos.z4.z4 +! CHECK: fir.call {{.*}}cos + +! CHECK-LABEL: @fir.cos.z8.z8 +! CHECK: fir.call {{.*}}cos + ! CHECK-LABEL: @fir.cosh.f32.f32 ! CHECK: fir.call {{.*}}cosh @@ -109,6 +177,18 @@ subroutine sinh_testcd(z) ! CHECK-LABEL: @fir.cosh.z8.z8 ! CHECK: fir.call {{.*}}cosh +! CHECK-LABEL: @fir.sin.f32.f32 +! CHECK: fir.call {{.*}}sin + +! CHECK-LABEL: @fir.sin.f64.f64 +! CHECK: fir.call {{.*}}sin + +! CHECK-LABEL: @fir.sin.z4.z4 +! CHECK: fir.call {{.*}}sin + +! CHECK-LABEL: @fir.sin.z8.z8 +! CHECK: fir.call {{.*}}sin + ! CHECK-LABEL: @fir.sinh.f32.f32 ! CHECK: fir.call {{.*}}sinh