[flang-commits] [flang] 4a8f1d6 - [flang] Lower 2-argument F2008 atan intrinsic
via flang-commits
flang-commits at lists.llvm.org
Thu Jul 11 06:24:46 PDT 2024
Author: Tarun Prabhu
Date: 2024-07-11T07:24:42-06:00
New Revision: 4a8f1d670f6135eaf4fabb6f5ed677e6cb571464
URL: https://github.com/llvm/llvm-project/commit/4a8f1d670f6135eaf4fabb6f5ed677e6cb571464
DIFF: https://github.com/llvm/llvm-project/commit/4a8f1d670f6135eaf4fabb6f5ed677e6cb571464.diff
LOG: [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.
Added:
flang/test/Lower/Intrinsics/atan.f90
Modified:
flang/lib/Optimizer/Builder/IntrinsicCall.cpp
flang/test/Lower/Intrinsics/atan_real16.f90
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index f4541bf30676a..fe7605d8ce4ba 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1059,6 +1059,12 @@ static constexpr MathOperation mathOperations[] = {
{"atan", "catan", genFuncType<Ty::Complex<8>, Ty::Complex<8>>, genLibCall},
{"atan", RTNAME_STRING(CAtanF128), FuncTypeComplex16Complex16,
genLibF128Call},
+ {"atan", "atan2f", genFuncType<Ty::Real<4>, Ty::Real<4>, Ty::Real<4>>,
+ genMathOp<mlir::math::Atan2Op>},
+ {"atan", "atan2", genFuncType<Ty::Real<8>, Ty::Real<8>, Ty::Real<8>>,
+ genMathOp<mlir::math::Atan2Op>},
+ {"atan", RTNAME_STRING(Atan2F128), FuncTypeReal16Real16Real16,
+ genLibF128Call},
{"atan2", "atan2f", genFuncType<Ty::Real<4>, Ty::Real<4>, Ty::Real<4>>,
genMathOp<mlir::math::Atan2Op>},
{"atan2", "atan2", genFuncType<Ty::Real<8>, Ty::Real<8>, Ty::Real<8>>,
diff --git a/flang/test/Lower/Intrinsics/atan.f90 b/flang/test/Lower/Intrinsics/atan.f90
new file mode 100644
index 0000000000000..cf595b4d95d1d
--- /dev/null
+++ b/flang/test/Lower/Intrinsics/atan.f90
@@ -0,0 +1,55 @@
+! Check that correct runtime calls are used.
+! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-RUNTIME %s
+! RUN: %flang_fc1 -mllvm -math-runtime=precise -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-RUNTIME %s
+
+! Check that the correct math dialect operations are used.
+! RUN: bbc -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-NORMAL %s
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck --check-prefixes=CHECK-NORMAL %s
+
+function test_real4(x)
+ real :: x, test_real4
+ test_real4 = atan(x)
+end function
+
+! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atanf({{.*}}) {{.*}}: (f32) -> f32
+! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan {{.*}} {{.*}}: f32
+
+function test_real8(x)
+ real(8) :: x, test_real8
+ test_real8 = atan(x)
+end function
+
+! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atan({{.*}}) {{.*}}: (f64) -> f64
+! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan {{.*}} {{.*}}: f64
+
+function test_complex4(x)
+ complex :: x, test_complex4
+ test_complex4 = atan(x)
+end function
+
+! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @catanf({{.*}}) {{.*}}: (!fir.complex<4>) -> !fir.complex<4>
+! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = fir.call @catanf({{.*}}) {{.*}}: (!fir.complex<4>) -> !fir.complex<4>
+
+function test_complex8(x)
+ complex(kind=8) :: x, test_complex8
+ test_complex8 = atan(x)
+end function
+
+! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @catan({{.*}}) {{.*}}: (!fir.complex<8>) -> !fir.complex<8>
+! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = fir.call @catan({{.*}}) {{.*}}: (!fir.complex<8>) -> !fir.complex<8>
+
+function test_real4_2(y, x)
+ real :: y, x, test_real4_2
+ test_real4_2 = atan(y, x)
+end function
+
+! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atan2f({{.*}}) {{.*}}: (f32, f32) -> f32
+! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan2 {{.*}} {{.*}}: f32
+
+function test_real8_2(y, x)
+ real(8) :: y, x, test_real8_2
+ test_real8_2 = atan(y, x)
+end function
+
+! CHECK-RUNTIME: {{%[A-Za-z0-9._]+}} = fir.call @atan2({{.*}}) {{.*}}: (f64, f64) -> f64
+! CHECK-NORMAL: {{%[A-Za-z0-9._]+}} = math.atan2 {{.*}} {{.*}}: f64
diff --git a/flang/test/Lower/Intrinsics/atan_real16.f90 b/flang/test/Lower/Intrinsics/atan_real16.f90
index 5c0c262711c61..3ae037307c32b 100644
--- a/flang/test/Lower/Intrinsics/atan_real16.f90
+++ b/flang/test/Lower/Intrinsics/atan_real16.f90
@@ -3,7 +3,18 @@
! RUN: bbc --math-runtime=precise -emit-fir %s -o - | FileCheck %s
! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
+function test_real16(x)
+ real(16) :: x, test_real16
+ test_real16 = atan(x)
+end function real16
+
+! CHECK-LABEL: @_QPtest_real16
! CHECK: fir.call @_FortranAAtanF128({{.*}}){{.*}}: (f128) -> f128
- real(16) :: a, b
- b = atan(a)
-end
+
+function test_real16_2(y, x)
+ real(16) :: y, x, test_real16
+ test_real16 = atan(y, x)
+end function real16_2
+
+! CHECK-LABEL: @_QPtest_real16
+! CHECK: fir.call @_FortranAAtan2F128({{.*}}){{.*}}: (f128, f128) -> f128
More information about the flang-commits
mailing list