Skip to content

Commit 4a8f1d6

Browse files
authored
[flang] Lower 2-argument F2008 atan intrinsic
Implement lowering and testing of the atan(y,x) form of the atan intrinsic. Since the standard specifies that the behavior of this form is identical to the atan2 intrinsic, everything is lowered to atan2. In addition to tests for the atan(y,x) intrinsic, tests for the atan(x) intrinsic were also added/updated.
1 parent 2fb53f3 commit 4a8f1d6

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,12 @@ static constexpr MathOperation mathOperations[] = {
10591059
{"atan", "catan", genFuncType<Ty::Complex<8>, Ty::Complex<8>>, genLibCall},
10601060
{"atan", RTNAME_STRING(CAtanF128), FuncTypeComplex16Complex16,
10611061
genLibF128Call},
1062+
{"atan", "atan2f", genFuncType<Ty::Real<4>, Ty::Real<4>, Ty::Real<4>>,
1063+
genMathOp<mlir::math::Atan2Op>},
1064+
{"atan", "atan2", genFuncType<Ty::Real<8>, Ty::Real<8>, Ty::Real<8>>,
1065+
genMathOp<mlir::math::Atan2Op>},
1066+
{"atan", RTNAME_STRING(Atan2F128), FuncTypeReal16Real16Real16,
1067+
genLibF128Call},
10621068
{"atan2", "atan2f", genFuncType<Ty::Real<4>, Ty::Real<4>, Ty::Real<4>>,
10631069
genMathOp<mlir::math::Atan2Op>},
10641070
{"atan2", "atan2", genFuncType<Ty::Real<8>, Ty::Real<8>, Ty::Real<8>>,

flang/test/Lower/Intrinsics/atan.f90

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
! Check that correct runtime calls are used.
2+
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-RUNTIME %s
3+
! RUN: %flang_fc1 -mllvm -math-runtime=precise -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-RUNTIME %s
4+
5+
! Check that the correct math dialect operations are used.
6+
! RUN: bbc -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-NORMAL %s
7+
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-NORMAL %s
8+
9+
function test_real4(x)
10+
real :: x, test_real4
11+
test_real4 = atan(x)
12+
end function
13+
14+
! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atanf({{.*}}) {{.*}}: (f32) -> f32
15+
! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan {{.*}} {{.*}}: f32
16+
17+
function test_real8(x)
18+
real(8) :: x, test_real8
19+
test_real8 = atan(x)
20+
end function
21+
22+
! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atan({{.*}}) {{.*}}: (f64) -> f64
23+
! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan {{.*}} {{.*}}: f64
24+
25+
function test_complex4(x)
26+
complex :: x, test_complex4
27+
test_complex4 = atan(x)
28+
end function
29+
30+
! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @catanf({{.*}}) {{.*}}: (!fir.complex<4>) -> !fir.complex<4>
31+
! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = fir.call @catanf({{.*}}) {{.*}}: (!fir.complex<4>) -> !fir.complex<4>
32+
33+
function test_complex8(x)
34+
complex(kind=8) :: x, test_complex8
35+
test_complex8 = atan(x)
36+
end function
37+
38+
! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @catan({{.*}}) {{.*}}: (!fir.complex<8>) -> !fir.complex<8>
39+
! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = fir.call @catan({{.*}}) {{.*}}: (!fir.complex<8>) -> !fir.complex<8>
40+
41+
function test_real4_2(y, x)
42+
real :: y, x, test_real4_2
43+
test_real4_2 = atan(y, x)
44+
end function
45+
46+
! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atan2f({{.*}}) {{.*}}: (f32, f32) -> f32
47+
! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan2 {{.*}} {{.*}}: f32
48+
49+
function test_real8_2(y, x)
50+
real(8) :: y, x, test_real8_2
51+
test_real8_2 = atan(y, x)
52+
end function
53+
54+
! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atan2({{.*}}) {{.*}}: (f64, f64) -> f64
55+
! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan2 {{.*}} {{.*}}: f64

flang/test/Lower/Intrinsics/atan_real16.f90

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
44
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
55

6+
function test_real16(x)
7+
real(16) :: x, test_real16
8+
test_real16 = atan(x)
9+
end function real16
10+
11+
! CHECK-LABEL: @_QPtest_real16
612
! CHECK: fir.call @_FortranAAtanF128({{.*}}){{.*}}: (f128) -> f128
7-
real(16) :: a, b
8-
b = atan(a)
9-
end
13+
14+
function test_real16_2(y, x)
15+
real(16) :: y, x, test_real16
16+
test_real16 = atan(y, x)
17+
end function real16_2
18+
19+
! CHECK-LABEL: @_QPtest_real16
20+
! CHECK: fir.call @_FortranAAtan2F128({{.*}}){{.*}}: (f128, f128) -> f128

0 commit comments

Comments
 (0)