[flang-commits] [flang] [llvm] [flang] Classify IEEE_ARITHMETIC elemental functions and operators as SIMPLE (PR #223254)
Šárka Holendová via flang-commits
flang-commits at lists.llvm.org
Tue Sep 22 03:59:31 PDT 2026
https://github.com/mlir-maiden updated https://github.com/llvm/llvm-project/pull/223254
>From ae6a5ddd9fbe25ab73f145948bed9ac7cfd01a6b Mon Sep 17 00:00:00 2001
From: Sarka Holendova <sarka.holendova at gmail.com>
Date: Sun, 13 Sep 2026 11:21:28 -0400
Subject: [PATCH 1/3] [flang] Classify IEEE_ARITHMETIC elemental functions as
SIMPLE
Fortran 2023 17.11.1 specifies IEEE_ARITHMETIC module functions as
`SIMPLE`.
This change:
- Adds the `SIMPLE` prefix to the elemental function interfaces
- Adds a symbol test to verify the added `SIMPLE` attribute
Part of the `SIMPLE` procedure support tracked in #221457.
---
flang-rt/lib/runtime/ieee_arithmetic.f90 | 58 +++++++++----------
.../simple-ieee-arithmetic-functions.f90 | 15 +++++
2 files changed, 44 insertions(+), 29 deletions(-)
create mode 100644 flang/test/Semantics/simple-ieee-arithmetic-functions.f90
diff --git a/flang-rt/lib/runtime/ieee_arithmetic.f90 b/flang-rt/lib/runtime/ieee_arithmetic.f90
index 02cfae2dc6b187..b189b661469d92 100644
--- a/flang-rt/lib/runtime/ieee_arithmetic.f90
+++ b/flang-rt/lib/runtime/ieee_arithmetic.f90
@@ -289,7 +289,7 @@ end function ieee_round_ne
#endif
#define IEEE_CLASS_R(XKIND) \
- elemental type(ieee_class_type) function ieee_class_a##XKIND(x); \
+ simple elemental type(ieee_class_type) function ieee_class_a##XKIND(x); \
import ieee_class_type; \
real(XKIND), intent(in) :: x; \
end function ieee_class_a##XKIND;
@@ -300,7 +300,7 @@ end function ieee_class_a##XKIND;
#undef IEEE_CLASS_R
#define IEEE_COPY_SIGN_RR(XKIND, YKIND) \
- elemental real(XKIND) function ieee_copy_sign_a##XKIND##_a##YKIND(x, y); \
+ simple elemental real(XKIND) function ieee_copy_sign_a##XKIND##_a##YKIND(x, y); \
real(XKIND), intent(in) :: x; \
real(YKIND), intent(in) :: y; \
end function ieee_copy_sign_a##XKIND##_a##YKIND;
@@ -337,7 +337,7 @@ end subroutine ieee_get_underflow_mode_l##GKIND;
#undef IEEE_GET_UNDERFLOW_MODE_L
#define IEEE_IS_FINITE_R(XKIND) \
- elemental logical function ieee_is_finite_a##XKIND(x); \
+ simple elemental logical function ieee_is_finite_a##XKIND(x); \
real(XKIND), intent(in) :: x; \
!dir$ ignore_tkr(d) x; \
end function ieee_is_finite_a##XKIND;
@@ -348,7 +348,7 @@ end function ieee_is_finite_a##XKIND;
#undef IEEE_IS_FINITE_R
#define IEEE_LOGB_R(XKIND) \
- elemental real(XKIND) function ieee_logb_a##XKIND(x); \
+ simple elemental real(XKIND) function ieee_logb_a##XKIND(x); \
real(XKIND), intent(in) :: x; \
end function ieee_logb_a##XKIND;
interface ieee_logb
@@ -358,7 +358,7 @@ end function ieee_logb_a##XKIND;
#undef IEEE_LOGB_R
#define IEEE_MAX_R(XKIND) \
- elemental real(XKIND) function ieee_max_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_max_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_max_a##XKIND;
interface ieee_max
@@ -368,7 +368,7 @@ end function ieee_max_a##XKIND;
#undef IEEE_MAX_R
#define IEEE_MAX_MAG_R(XKIND) \
- elemental real(XKIND) function ieee_max_mag_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_max_mag_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_max_mag_a##XKIND;
interface ieee_max_mag
@@ -378,7 +378,7 @@ end function ieee_max_mag_a##XKIND;
#undef IEEE_MAX_MAG_R
#define IEEE_MAX_NUM_R(XKIND) \
- elemental real(XKIND) function ieee_max_num_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_max_num_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_max_num_a##XKIND;
interface ieee_max_num
@@ -388,7 +388,7 @@ end function ieee_max_num_a##XKIND;
#undef IEEE_MAX_NUM_R
#define IEEE_MAX_NUM_MAG_R(XKIND) \
- elemental real(XKIND) function ieee_max_num_mag_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_max_num_mag_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_max_num_mag_a##XKIND;
interface ieee_max_num_mag
@@ -398,7 +398,7 @@ end function ieee_max_num_mag_a##XKIND;
#undef IEEE_MAX_NUM_MAG_R
#define IEEE_MIN_R(XKIND) \
- elemental real(XKIND) function ieee_min_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_min_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_min_a##XKIND;
interface ieee_min
@@ -408,7 +408,7 @@ end function ieee_min_a##XKIND;
#undef IEEE_MIN_R
#define IEEE_MIN_MAG_R(XKIND) \
- elemental real(XKIND) function ieee_min_mag_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_min_mag_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_min_mag_a##XKIND;
interface ieee_min_mag
@@ -418,7 +418,7 @@ end function ieee_min_mag_a##XKIND;
#undef IEEE_MIN_MAG_R
#define IEEE_MIN_NUM_R(XKIND) \
- elemental real(XKIND) function ieee_min_num_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_min_num_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_min_num_a##XKIND;
interface ieee_min_num
@@ -428,7 +428,7 @@ end function ieee_min_num_a##XKIND;
#undef IEEE_MIN_NUM_R
#define IEEE_MIN_NUM_MAG_R(XKIND) \
- elemental real(XKIND) function ieee_min_num_mag_a##XKIND(x, y); \
+ simple elemental real(XKIND) function ieee_min_num_mag_a##XKIND(x, y); \
real(XKIND), intent(in) :: x, y; \
end function ieee_min_num_mag_a##XKIND;
interface ieee_min_num_mag
@@ -438,7 +438,7 @@ end function ieee_min_num_mag_a##XKIND;
#undef IEEE_MIN_NUM_MAG_R
#define IEEE_QUIET_EQ_R(AKIND) \
- elemental logical function ieee_quiet_eq_a##AKIND(a, b); \
+ simple elemental logical function ieee_quiet_eq_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_quiet_eq_a##AKIND;
interface ieee_quiet_eq
@@ -448,7 +448,7 @@ end function ieee_quiet_eq_a##AKIND;
#undef IEEE_QUIET_EQ_R
#define IEEE_QUIET_GE_R(AKIND) \
- elemental logical function ieee_quiet_ge_a##AKIND(a, b); \
+ simple elemental logical function ieee_quiet_ge_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_quiet_ge_a##AKIND;
interface ieee_quiet_ge
@@ -458,7 +458,7 @@ end function ieee_quiet_ge_a##AKIND;
#undef IEEE_QUIET_GE_R
#define IEEE_QUIET_GT_R(AKIND) \
- elemental logical function ieee_quiet_gt_a##AKIND(a, b); \
+ simple elemental logical function ieee_quiet_gt_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_quiet_gt_a##AKIND;
interface ieee_quiet_gt
@@ -468,7 +468,7 @@ end function ieee_quiet_gt_a##AKIND;
#undef IEEE_QUIET_GT_R
#define IEEE_QUIET_LE_R(AKIND) \
- elemental logical function ieee_quiet_le_a##AKIND(a, b); \
+ simple elemental logical function ieee_quiet_le_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_quiet_le_a##AKIND;
interface ieee_quiet_le
@@ -478,7 +478,7 @@ end function ieee_quiet_le_a##AKIND;
#undef IEEE_QUIET_LE_R
#define IEEE_QUIET_LT_R(AKIND) \
- elemental logical function ieee_quiet_lt_a##AKIND(a, b); \
+ simple elemental logical function ieee_quiet_lt_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_quiet_lt_a##AKIND;
interface ieee_quiet_lt
@@ -488,7 +488,7 @@ end function ieee_quiet_lt_a##AKIND;
#undef IEEE_QUIET_LT_R
#define IEEE_QUIET_NE_R(AKIND) \
- elemental logical function ieee_quiet_ne_a##AKIND(a, b); \
+ simple elemental logical function ieee_quiet_ne_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_quiet_ne_a##AKIND;
interface ieee_quiet_ne
@@ -498,7 +498,7 @@ end function ieee_quiet_ne_a##AKIND;
#undef IEEE_QUIET_NE_R
#define IEEE_REM_rRR(RKIND, XKIND, YKIND) \
- elemental real(RKIND) function ieee_rem_a##XKIND##_a##YKIND(x, y); \
+ simple elemental real(RKIND) function ieee_rem_a##XKIND##_a##YKIND(x, y); \
real(XKIND), intent(in) :: x; \
real(YKIND), intent(in) :: y; \
end function ieee_rem_a##XKIND##_a##YKIND;
@@ -509,7 +509,7 @@ end function ieee_rem_a##XKIND##_a##YKIND;
#undef IEEE_REM_rRR
#define IEEE_RINT_R(XKIND) \
- elemental real(XKIND) function ieee_rint_a##XKIND(x, round); \
+ simple elemental real(XKIND) function ieee_rint_a##XKIND(x, round); \
import ieee_round_type; \
real(XKIND), intent(in) :: x; \
type(ieee_round_type), optional, intent(in) :: round; \
@@ -547,7 +547,7 @@ end subroutine ieee_set_underflow_mode_l##GKIND;
#undef IEEE_SET_UNDERFLOW_MODE_L
#define IEEE_SIGNALING_EQ_R(AKIND) \
- elemental logical function ieee_signaling_eq_a##AKIND(a, b); \
+ simple elemental logical function ieee_signaling_eq_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_signaling_eq_a##AKIND;
interface ieee_signaling_eq
@@ -557,7 +557,7 @@ end function ieee_signaling_eq_a##AKIND;
#undef IEEE_SIGNALING_EQ_R
#define IEEE_SIGNALING_GE_R(AKIND) \
- elemental logical function ieee_signaling_ge_a##AKIND(a, b); \
+ simple elemental logical function ieee_signaling_ge_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_signaling_ge_a##AKIND;
interface ieee_signaling_ge
@@ -567,7 +567,7 @@ end function ieee_signaling_ge_a##AKIND;
#undef IEEE_SIGNALING_GE_R
#define IEEE_SIGNALING_GT_R(AKIND) \
- elemental logical function ieee_signaling_gt_a##AKIND(a, b); \
+ simple elemental logical function ieee_signaling_gt_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_signaling_gt_a##AKIND;
interface ieee_signaling_gt
@@ -577,7 +577,7 @@ end function ieee_signaling_gt_a##AKIND;
#undef IEEE_SIGNALING_GT_R
#define IEEE_SIGNALING_LE_R(AKIND) \
- elemental logical function ieee_signaling_le_a##AKIND(a, b); \
+ simple elemental logical function ieee_signaling_le_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_signaling_le_a##AKIND;
interface ieee_signaling_le
@@ -587,7 +587,7 @@ end function ieee_signaling_le_a##AKIND;
#undef IEEE_SIGNALING_LE_R
#define IEEE_SIGNALING_LT_R(AKIND) \
- elemental logical function ieee_signaling_lt_a##AKIND(a, b); \
+ simple elemental logical function ieee_signaling_lt_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_signaling_lt_a##AKIND;
interface ieee_signaling_lt
@@ -597,7 +597,7 @@ end function ieee_signaling_lt_a##AKIND;
#undef IEEE_SIGNALING_LT_R
#define IEEE_SIGNALING_NE_R(AKIND) \
- elemental logical function ieee_signaling_ne_a##AKIND(a, b); \
+ simple elemental logical function ieee_signaling_ne_a##AKIND(a, b); \
real(AKIND), intent(in) :: a, b; \
end function ieee_signaling_ne_a##AKIND;
interface ieee_signaling_ne
@@ -607,7 +607,7 @@ end function ieee_signaling_ne_a##AKIND;
#undef IEEE_SIGNALING_NE_R
#define IEEE_SIGNBIT_R(XKIND) \
- elemental logical function ieee_signbit_a##XKIND(x); \
+ simple elemental logical function ieee_signbit_a##XKIND(x); \
real(XKIND), intent(in) :: x; \
end function ieee_signbit_a##XKIND;
interface ieee_signbit
@@ -617,7 +617,7 @@ end function ieee_signbit_a##XKIND;
#undef IEEE_SIGNBIT_R
#define IEEE_UNORDERED_RR(XKIND, YKIND) \
- elemental logical function ieee_unordered_a##XKIND##_a##YKIND(x, y); \
+ simple elemental logical function ieee_unordered_a##XKIND##_a##YKIND(x, y); \
real(XKIND), intent(in) :: x; \
real(YKIND), intent(in) :: y; \
end function ieee_unordered_a##XKIND##_a##YKIND;
@@ -628,7 +628,7 @@ end function ieee_unordered_a##XKIND##_a##YKIND;
#undef IEEE_UNORDERED_RR
#define IEEE_VALUE_R(XKIND) \
- elemental real(XKIND) function ieee_value_a##XKIND(x, class); \
+ simple elemental real(XKIND) function ieee_value_a##XKIND(x, class); \
import ieee_class_type; \
real(XKIND), intent(in) :: x; \
type(ieee_class_type), intent(in) :: class; \
diff --git a/flang/test/Semantics/simple-ieee-arithmetic-functions.f90 b/flang/test/Semantics/simple-ieee-arithmetic-functions.f90
new file mode 100644
index 00000000000000..2b0f544aa2e900
--- /dev/null
+++ b/flang/test/Semantics/simple-ieee-arithmetic-functions.f90
@@ -0,0 +1,15 @@
+! Test that IEEE_ARITHMETIC module functions are classified SIMPLE.
+! RUN: %python %S/test_symbols.py %s %flang_fc1
+
+!DEF: /TEST_IEEE_ARITHMETIC_SIMPLE MainProgram
+program TEST_IEEE_ARITHMETIC_SIMPLE
+ !DEF: /ieee_arithmetic INTRINSIC (ModFile) Module
+ !DEF: /ieee_arithmetic/ieee_is_finite PUBLIC (Function) Generic
+ use :: ieee_arithmetic, only: ieee_is_finite
+ implicit none
+ !DEF: /TEST_IEEE_ARITHMETIC_SIMPLE/x ObjectEntity LOGICAL(4)
+ logical x
+ !REF: /TEST_IEEE_ARITHMETIC_SIMPLE/x
+ !DEF: /TEST_IEEE_ARITHMETIC_SIMPLE/ieee_arithmetic$ieee_arithmetic$ieee_is_finite_a4 ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE Use LOGICAL(4)
+ x = ieee_is_finite(1.0)
+end program
>From 309db293b282d41777db19a35a289e6631efafb2 Mon Sep 17 00:00:00 2001
From: Sarka Holendova <sarka.holendova at gmail.com>
Date: Sat, 19 Sep 2026 11:44:50 -0400
Subject: [PATCH 2/3] [flang] Classify IEEE_ARITHMETIC operators as SIMPLE
Classify the elemental == and /= operators for ieee_class_type and
ieee_round_type as SIMPLE, and add tests.
---
flang-rt/lib/runtime/ieee_arithmetic.f90 | 8 ++++----
.../simple-ieee-arithmetic-operators.f90 | 20 +++++++++++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
create mode 100644 flang/test/Semantics/simple-ieee-arithmetic-operators.f90
diff --git a/flang-rt/lib/runtime/ieee_arithmetic.f90 b/flang-rt/lib/runtime/ieee_arithmetic.f90
index b189b661469d92..0e7d4493385f54 100644
--- a/flang-rt/lib/runtime/ieee_arithmetic.f90
+++ b/flang-rt/lib/runtime/ieee_arithmetic.f90
@@ -136,11 +136,11 @@ module ieee_arithmetic
ieee_positive_denormal = ieee_positive_subnormal
interface operator(==)
- elemental logical function ieee_class_eq(x, y)
+ simple elemental logical function ieee_class_eq(x, y)
import ieee_class_type
type(ieee_class_type), intent(in) :: x, y
end function ieee_class_eq
- elemental logical function ieee_round_eq(x, y)
+ simple elemental logical function ieee_round_eq(x, y)
import ieee_round_type
type(ieee_round_type), intent(in) :: x, y
end function ieee_round_eq
@@ -148,11 +148,11 @@ end function ieee_round_eq
public :: operator(==)
interface operator(/=)
- elemental logical function ieee_class_ne(x, y)
+ simple elemental logical function ieee_class_ne(x, y)
import ieee_class_type
type(ieee_class_type), intent(in) :: x, y
end function ieee_class_ne
- elemental logical function ieee_round_ne(x, y)
+ simple elemental logical function ieee_round_ne(x, y)
import ieee_round_type
type(ieee_round_type), intent(in) :: x, y
end function ieee_round_ne
diff --git a/flang/test/Semantics/simple-ieee-arithmetic-operators.f90 b/flang/test/Semantics/simple-ieee-arithmetic-operators.f90
new file mode 100644
index 00000000000000..88a843164248b4
--- /dev/null
+++ b/flang/test/Semantics/simple-ieee-arithmetic-operators.f90
@@ -0,0 +1,20 @@
+! Test that IEEE_ARITHMETIC equality and inequality operators are classified SIMPLE
+! RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
+
+program test_ieee_arithmetic_operators
+ use, intrinsic :: ieee_arithmetic, only: ieee_class_type, ieee_round_type, &
+ operator(==), operator(/=)
+ implicit none
+ type(ieee_class_type) :: class1, class2
+ type(ieee_round_type) :: round1, round2
+ logical :: result
+ result = class1 == class2
+ result = class1 /= class2
+ result = round1 == round2
+ result = round1 /= round2
+end program
+
+! CHECK: ieee_class_eq, ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE (Function):
+! CHECK: ieee_class_ne, ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE (Function):
+! CHECK: ieee_round_eq, ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE (Function):
+! CHECK: ieee_round_ne, ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE (Function):
>From 2234e62f5a0a3dccb82fd509bd52f00155a3b989 Mon Sep 17 00:00:00 2001
From: Sarka Holendova <sarka.holendova at gmail.com>
Date: Tue, 22 Sep 2026 06:58:47 -0400
Subject: [PATCH 3/3] [flang] Use FileCheck for IEEE SIMPLE function test
---
.../simple-ieee-arithmetic-functions.f90 | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/flang/test/Semantics/simple-ieee-arithmetic-functions.f90 b/flang/test/Semantics/simple-ieee-arithmetic-functions.f90
index 2b0f544aa2e900..fbd4a9386bdc5a 100644
--- a/flang/test/Semantics/simple-ieee-arithmetic-functions.f90
+++ b/flang/test/Semantics/simple-ieee-arithmetic-functions.f90
@@ -1,15 +1,10 @@
-! Test that IEEE_ARITHMETIC module functions are classified SIMPLE.
-! RUN: %python %S/test_symbols.py %s %flang_fc1
+! Test that IEEE_ARITHMETIC module functions are classified SIMPLE
+! RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
-!DEF: /TEST_IEEE_ARITHMETIC_SIMPLE MainProgram
-program TEST_IEEE_ARITHMETIC_SIMPLE
- !DEF: /ieee_arithmetic INTRINSIC (ModFile) Module
- !DEF: /ieee_arithmetic/ieee_is_finite PUBLIC (Function) Generic
- use :: ieee_arithmetic, only: ieee_is_finite
+program test_ieee_arithmetic_simple
+ use, intrinsic :: ieee_arithmetic, only: ieee_is_finite
implicit none
- !DEF: /TEST_IEEE_ARITHMETIC_SIMPLE/x ObjectEntity LOGICAL(4)
- logical x
- !REF: /TEST_IEEE_ARITHMETIC_SIMPLE/x
- !DEF: /TEST_IEEE_ARITHMETIC_SIMPLE/ieee_arithmetic$ieee_arithmetic$ieee_is_finite_a4 ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE Use LOGICAL(4)
+ logical :: x
x = ieee_is_finite(1.0)
end program
+! CHECK: ieee_is_finite_a4, ELEMENTAL, EXTERNAL, PRIVATE, SIMPLE (Function):
More information about the flang-commits
mailing list