[flang-commits] [flang] [flang] Modifications to ieee_support_standard (PR #128895)

via flang-commits flang-commits at lists.llvm.org
Wed Feb 26 07:51:57 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: None (vdonaldson)

<details>
<summary>Changes</summary>

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
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,

``````````

</details>


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


More information about the flang-commits mailing list