-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[flang] Support calling ieee_support_flag with an array argument #93772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If present, the optional second argument of the ieee_exceptions intrinsic module procedure ieee_support_flag may be either a scalar or an array. Change the signature of the routine that implements this function so that it is processed as a transformational function, not an elemental function, which accounts for this argument variant.
@llvm/pr-subscribers-flang-fir-hlfir Author: None (vdonaldson) ChangesIf present, the optional second argument of the ieee_exceptions intrinsic module procedure ieee_support_flag may be either a scalar or an array. Change the signature of the routine that implements this function so that it is processed as a transformational function, not an elemental function, which accounts for this argument variant. Full diff: https://github.com/llvm/llvm-project/pull/93772.diff 3 Files Affected:
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 357df3b6df50d..c47e41eab18b2 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -271,8 +271,9 @@ struct IntrinsicLibrary {
mlir::Value genIeeeSignalingCompare(mlir::Type resultType,
llvm::ArrayRef<mlir::Value>);
mlir::Value genIeeeSignbit(mlir::Type, llvm::ArrayRef<mlir::Value>);
- mlir::Value genIeeeSupportFlagOrHalting(mlir::Type,
- llvm::ArrayRef<mlir::Value>);
+ fir::ExtendedValue
+ genIeeeSupportFlagOrHalting(mlir::Type,
+ llvm::ArrayRef<fir::ExtendedValue>);
mlir::Value genIeeeSupportRounding(mlir::Type, llvm::ArrayRef<mlir::Value>);
template <mlir::arith::CmpIPredicate pred>
mlir::Value genIeeeTypeCompare(mlir::Type, llvm::ArrayRef<mlir::Value>);
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index ad2f9236f0db9..1cd3976d0afbe 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -368,7 +368,10 @@ static constexpr IntrinsicHandler handlers[]{
{"ieee_signaling_ne",
&I::genIeeeSignalingCompare<mlir::arith::CmpFPredicate::UNE>},
{"ieee_signbit", &I::genIeeeSignbit},
- {"ieee_support_flag", &I::genIeeeSupportFlagOrHalting},
+ {"ieee_support_flag",
+ &I::genIeeeSupportFlagOrHalting,
+ {{{"flag", asValue}, {"x", asInquired, handleDynamicOptional}}},
+ /*isElemental=*/false},
{"ieee_support_halting", &I::genIeeeSupportFlagOrHalting},
{"ieee_support_rounding", &I::genIeeeSupportRounding},
{"ieee_unordered", &I::genIeeeUnordered},
@@ -4672,15 +4675,15 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType,
}
// IEEE_SUPPORT_FLAG, IEEE_SUPPORT_HALTING
-mlir::Value IntrinsicLibrary::genIeeeSupportFlagOrHalting(
- mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) {
+fir::ExtendedValue IntrinsicLibrary::genIeeeSupportFlagOrHalting(
+ mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) {
// Check if a floating point exception or halting mode FLAG is supported.
// An IEEE_SUPPORT_FLAG flag is supported either for all type kinds or none.
// An optional kind argument X is therefore ignored.
// Standard flags are all supported.
// The nonstandard DENORM extension is not supported. (At least for now.)
assert(args.size() == 1 || args.size() == 2);
- auto [fieldRef, fieldTy] = getFieldRef(builder, loc, args[0]);
+ auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0]));
mlir::Value flag = builder.create<fir::LoadOp>(loc, fieldRef);
mlir::Value mask = builder.createIntegerConstant( // values are powers of 2
loc, fieldTy,
diff --git a/flang/test/Lower/Intrinsics/ieee_flag.f90 b/flang/test/Lower/Intrinsics/ieee_flag.f90
index 7cd24c07ce9bd..424f8d5b29530 100644
--- a/flang/test/Lower/Intrinsics/ieee_flag.f90
+++ b/flang/test/Lower/Intrinsics/ieee_flag.f90
@@ -20,6 +20,7 @@
! CHECK: %[[V_63:[0-9]+]] = fir.alloca !fir.array<3x!fir.logical<4>> {bindc_name = "v_usual", uniq_name = "_QFEv_usual"}
! CHECK: %[[V_64:[0-9]+]] = fir.declare %[[V_63]](%[[V_54]]) {uniq_name = "_QFEv_usual"} : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> !fir.ref<!fir.array<3x!fir.logical<4>>>
logical :: v, v2(2), v_usual(size(ieee_usual)), v_all(size(ieee_all))
+ real :: x(100,20,10)
! CHECK: %[[V_67:[0-9]+]] = fir.call @_FortranAioBeginExternalListOutput
print*, 'Flag'
@@ -40,7 +41,7 @@
! CHECK: %[[V_92:[0-9]+]] = arith.cmpi ne, %[[V_91]], %c0{{.*}} : i8
! CHECK: %[[V_93:[0-9]+]] = fir.call @_FortranAioOutputLogical(%[[V_74]], %[[V_92]]) fastmath<contract> : (!fir.ref<i8>, i1) -> i1
print*, 'support invalid: ', &
- ieee_support_flag(ieee_invalid), ieee_support_flag(ieee_invalid, 0.)
+ ieee_support_flag(ieee_invalid), ieee_support_flag(ieee_invalid, x)
! CHECK: %[[V_95:[0-9]+]] = fir.declare %[[V_80]] {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QQro._QM__fortran_ieee_exceptionsTieee_flag_type.0"} : (!fir.ref<!fir.type<_QM__fortran_ieee_exceptionsTieee_flag_type{_QM__fortran_ieee_exceptionsTieee_flag_type.flag:i8}>>) -> !fir.ref<!fir.type<_QM__fortran_ieee_exceptionsTieee_flag_type{_QM__fortran_ieee_exceptionsTieee_flag_type.flag:i8}>>
! CHECK: %[[V_96:[0-9]+]] = fir.coordinate_of %[[V_95]], %[[V_82]] : (!fir.ref<!fir.type<_QM__fortran_ieee_exceptionsTieee_flag_type{_QM__fortran_ieee_exceptionsTieee_flag_type.flag:i8}>>, !fir.field) -> !fir.ref<i8>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All builds and tests correctly and looks good.
If present, the optional second argument of the ieee_exceptions intrinsic module procedure ieee_support_flag may be either a scalar or an array. Change the signature of the routine that implements this function so that it is processed as a transformational function, not an elemental function, which accounts for this argument variant.