Skip to content

[flang] Modifications to ieee_support_standard #128895

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

Merged
merged 2 commits into from
Feb 27, 2025
Merged

Conversation

vdonaldson
Copy link
Contributor

Some Arm processors support exception halting control and some do not. An Arm executable will run on either type of processor, so it is effectively unknown at compile time whether or not this support will be available. ieee_support_halting is therefore implemented with a runtime check.

The result of a call to ieee_support_standard depends in part on support for halting control. Update the ieee_support_standard implementation to check for support for halting control at runtime.

Some Arm processors support exception halting control and some do not.
An Arm executable will run on either type of processor, so it is effectively
unknown at compile time whether or not this support will be available.
ieee_support_halting is therefore implemented with a runtime check.

The result of a call to ieee_support_standard depends in part on support
for halting control. Update the ieee_support_standard implementation to
check for support for halting control at runtime.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Feb 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 26, 2025

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-fir-hlfir

Author: None (vdonaldson)

Changes

Some Arm processors support exception halting control and some do not. An Arm executable will run on either type of processor, so it is effectively unknown at compile time whether or not this support will be available. ieee_support_halting is therefore implemented with a runtime check.

The result of a call to ieee_support_standard depends in part on support for halting control. Update the ieee_support_standard implementation to check for support for halting control at runtime.


Full diff: https://github.com/llvm/llvm-project/pull/128895.diff

4 Files Affected:

  • (modified) flang/docs/Extensions.md (+5-3)
  • (modified) flang/include/flang/Optimizer/Builder/IntrinsicCall.h (+2)
  • (modified) flang/lib/Evaluate/fold-logical.cpp (+7-3)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+14)
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 1dc0b65271b27..e70f40306c4e1 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -150,13 +150,15 @@ end
   have this capability. An Arm executable will run on either type of
   processor, so it is effectively unknown at compile time whether or
   not this support will be available at runtime. The standard requires
-  that a call to intrinsic module procedure `IEEE_SUPPORT_HALTING` with
+  that a call to intrinsic module procedure `ieee_support_halting` with
   a constant argument has a compile time constant result in `constant
   expression` and `specification expression` contexts. In compilations
   where this information is not known at compile time, f18 generates code
   to determine the absence or presence of this capability at runtime.
-  A call to `IEEE_SUPPORT_HALTING` in contexts that the standard requires
-  to be constant will generate a compilation error.
+  A call to `ieee_support_halting` in contexts that the standard requires
+  to be constant will generate a compilation error. `ieee_support_standard`
+  depends in part on `ieee_support_halting`, so this also applies to
+  `ieee_support_standard` calls.
 
 ## Extensions, deletions, and legacy features supported by default
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index f5971610694f0..7ea05153e7043 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -314,6 +314,8 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genIeeeSupportHalting(mlir::Type,
                                            llvm::ArrayRef<fir::ExtendedValue>);
   mlir::Value genIeeeSupportRounding(mlir::Type, llvm::ArrayRef<mlir::Value>);
+  fir::ExtendedValue genIeeeSupportStandard(mlir::Type,
+                                            llvm::ArrayRef<fir::ExtendedValue>);
   template <mlir::arith::CmpIPredicate pred>
   mlir::Value genIeeeTypeCompare(mlir::Type, llvm::ArrayRef<mlir::Value>);
   mlir::Value genIeeeUnordered(mlir::Type, llvm::ArrayRef<mlir::Value>);
diff --git a/flang/lib/Evaluate/fold-logical.cpp b/flang/lib/Evaluate/fold-logical.cpp
index e3ec1a1af8881..77f8e0f616878 100644
--- a/flang/lib/Evaluate/fold-logical.cpp
+++ b/flang/lib/Evaluate/fold-logical.cpp
@@ -882,7 +882,7 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
         IeeeFeature::Flags)};
   } else if (name == "__builtin_ieee_support_halting") {
     if (!context.targetCharacteristics()
-             .haltingSupportIsUnknownAtCompileTime()) {
+            .haltingSupportIsUnknownAtCompileTime()) {
       return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
           IeeeFeature::Halting)};
     }
@@ -906,8 +906,12 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
     return Expr<T>{
         context.targetCharacteristics().ieeeFeatures().test(IeeeFeature::Sqrt)};
   } else if (name == "__builtin_ieee_support_standard") {
-    return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
-        IeeeFeature::Standard)};
+    // ieee_support_standard depends in part on ieee_support_halting.
+    if (!context.targetCharacteristics()
+            .haltingSupportIsUnknownAtCompileTime()) {
+      return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
+          IeeeFeature::Standard)};
+    }
   } else if (name == "__builtin_ieee_support_subnormal") {
     return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
         IeeeFeature::Subnormal)};
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 537c817e32ad8..a4f4475ffe173 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -458,6 +458,7 @@ static constexpr IntrinsicHandler handlers[]{
      /*isElemental=*/false},
     {"ieee_support_halting", &I::genIeeeSupportHalting},
     {"ieee_support_rounding", &I::genIeeeSupportRounding},
+    {"ieee_support_standard", &I::genIeeeSupportStandard},
     {"ieee_unordered", &I::genIeeeUnordered},
     {"ieee_value", &I::genIeeeValue},
     {"ieor", &I::genIeor},
@@ -5671,6 +5672,19 @@ IntrinsicLibrary::genIeeeSupportRounding(mlir::Type resultType,
       loc, resultType, builder.create<mlir::arith::AndIOp>(loc, lbOk, ubOk));
 }
 
+// IEEE_SUPPORT_STANDARD
+fir::ExtendedValue IntrinsicLibrary::genIeeeSupportStandard(
+    mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) {
+  // Check if IEEE standard support is available, which reduces to checking
+  // if halting control is supported, as that is the only support component
+  // that may not be available.
+  assert(args.size() <= 1);
+  mlir::Value nearest = builder.createIntegerConstant(
+      loc, builder.getIntegerType(32), _FORTRAN_RUNTIME_IEEE_NEAREST);
+  return builder.createConvert(
+      loc, resultType, fir::runtime::genSupportHalting(builder, loc, nearest));
+}
+
 // IEEE_UNORDERED
 mlir::Value
 IntrinsicLibrary::genIeeeUnordered(mlir::Type resultType,

@tblah
Copy link
Contributor

tblah commented Feb 26, 2025

Hi, thank you for the patch.

After this patch, two Fujitsu tests now fail to build: 0136_0046.f90 and 0136_0047.f90. The error message complains that ieee_support_standrard(x) must be a scalar value, but is a rank-1 array.

Procedure ieee_support_standard is an inquiry function, not an elemental
function. Account for that, and make similar adjustments for other inquiry
and transformational functions.
@vdonaldson
Copy link
Contributor Author

After this patch, two Fujitsu tests now fail to build: 0136_0046.f90 and 0136_0047.f90. The error message complains that ieee_support_standrard(x) must be a scalar value, but is a rank-1 array.

Thanks for catching this. I've updated the code to treat ieee_support_standard and similar procedures as inquiry or transformational functions, as appropriate, rather than as elemental functions.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. This resolves the issue I mentioned.

@vdonaldson vdonaldson merged commit 62d4cc8 into llvm:main Feb 27, 2025
12 checks passed
@vdonaldson vdonaldson deleted the vkd1 branch March 7, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants