Skip to content

Commit 6179036

Browse files
authored
[flang] Support calling ieee_support_flag with an array argument (#93772)
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.
1 parent 2b9c158 commit 6179036

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ struct IntrinsicLibrary {
271271
mlir::Value genIeeeSignalingCompare(mlir::Type resultType,
272272
llvm::ArrayRef<mlir::Value>);
273273
mlir::Value genIeeeSignbit(mlir::Type, llvm::ArrayRef<mlir::Value>);
274-
mlir::Value genIeeeSupportFlagOrHalting(mlir::Type,
275-
llvm::ArrayRef<mlir::Value>);
274+
fir::ExtendedValue
275+
genIeeeSupportFlagOrHalting(mlir::Type,
276+
llvm::ArrayRef<fir::ExtendedValue>);
276277
mlir::Value genIeeeSupportRounding(mlir::Type, llvm::ArrayRef<mlir::Value>);
277278
template <mlir::arith::CmpIPredicate pred>
278279
mlir::Value genIeeeTypeCompare(mlir::Type, llvm::ArrayRef<mlir::Value>);

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ static constexpr IntrinsicHandler handlers[]{
368368
{"ieee_signaling_ne",
369369
&I::genIeeeSignalingCompare<mlir::arith::CmpFPredicate::UNE>},
370370
{"ieee_signbit", &I::genIeeeSignbit},
371-
{"ieee_support_flag", &I::genIeeeSupportFlagOrHalting},
371+
{"ieee_support_flag",
372+
&I::genIeeeSupportFlagOrHalting,
373+
{{{"flag", asValue}, {"x", asInquired, handleDynamicOptional}}},
374+
/*isElemental=*/false},
372375
{"ieee_support_halting", &I::genIeeeSupportFlagOrHalting},
373376
{"ieee_support_rounding", &I::genIeeeSupportRounding},
374377
{"ieee_unordered", &I::genIeeeUnordered},
@@ -4672,15 +4675,15 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType,
46724675
}
46734676

46744677
// IEEE_SUPPORT_FLAG, IEEE_SUPPORT_HALTING
4675-
mlir::Value IntrinsicLibrary::genIeeeSupportFlagOrHalting(
4676-
mlir::Type resultType, llvm::ArrayRef<mlir::Value> args) {
4678+
fir::ExtendedValue IntrinsicLibrary::genIeeeSupportFlagOrHalting(
4679+
mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) {
46774680
// Check if a floating point exception or halting mode FLAG is supported.
46784681
// An IEEE_SUPPORT_FLAG flag is supported either for all type kinds or none.
46794682
// An optional kind argument X is therefore ignored.
46804683
// Standard flags are all supported.
46814684
// The nonstandard DENORM extension is not supported. (At least for now.)
46824685
assert(args.size() == 1 || args.size() == 2);
4683-
auto [fieldRef, fieldTy] = getFieldRef(builder, loc, args[0]);
4686+
auto [fieldRef, fieldTy] = getFieldRef(builder, loc, fir::getBase(args[0]));
46844687
mlir::Value flag = builder.create<fir::LoadOp>(loc, fieldRef);
46854688
mlir::Value mask = builder.createIntegerConstant( // values are powers of 2
46864689
loc, fieldTy,

flang/test/Lower/Intrinsics/ieee_flag.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
! CHECK: %[[V_63:[0-9]+]] = fir.alloca !fir.array<3x!fir.logical<4>> {bindc_name = "v_usual", uniq_name = "_QFEv_usual"}
2121
! 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>>>
2222
logical :: v, v2(2), v_usual(size(ieee_usual)), v_all(size(ieee_all))
23+
real :: x(100,20,10)
2324

2425
! CHECK: %[[V_67:[0-9]+]] = fir.call @_FortranAioBeginExternalListOutput
2526
print*, 'Flag'
@@ -40,7 +41,7 @@
4041
! CHECK: %[[V_92:[0-9]+]] = arith.cmpi ne, %[[V_91]], %c0{{.*}} : i8
4142
! CHECK: %[[V_93:[0-9]+]] = fir.call @_FortranAioOutputLogical(%[[V_74]], %[[V_92]]) fastmath<contract> : (!fir.ref<i8>, i1) -> i1
4243
print*, 'support invalid: ', &
43-
ieee_support_flag(ieee_invalid), ieee_support_flag(ieee_invalid, 0.)
44+
ieee_support_flag(ieee_invalid), ieee_support_flag(ieee_invalid, x)
4445

4546
! 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}>>
4647
! 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>

0 commit comments

Comments
 (0)