[flang-commits] [flang] 92afe80 - [flang] Fold SPACING() correctly when result is subnormal
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Aug 18 14:24:51 PDT 2022
Author: Peter Klausler
Date: 2022-08-18T14:24:38-07:00
New Revision: 92afe8021352ef33a282046d404a1f14140f96f9
URL: https://github.com/llvm/llvm-project/commit/92afe8021352ef33a282046d404a1f14140f96f9
DIFF: https://github.com/llvm/llvm-project/commit/92afe8021352ef33a282046d404a1f14140f96f9.diff
LOG: [flang] Fold SPACING() correctly when result is subnormal
The intrinsic function SPACING() was being folded to the smallest
normal number (TINY(x)) rather than to a smaller subnormal result
when that result really was subnormal.
Differential Revision: https://reviews.llvm.org/D132155
Added:
Modified:
flang/lib/Evaluate/real.cpp
flang/test/Evaluate/fold-spacing.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/real.cpp b/flang/lib/Evaluate/real.cpp
index 0af0ef2bf945b..ca0f4fd4bee7a 100644
--- a/flang/lib/Evaluate/real.cpp
+++ b/flang/lib/Evaluate/real.cpp
@@ -749,8 +749,7 @@ template <typename W, int P> Real<W, P> Real<W, P>::SPACING() const {
return TINY();
} else {
Real result;
- result.Normalize(
- false, Exponent() - binaryPrecision + 1, Fraction::MASKL(1));
+ result.Normalize(false, Exponent(), Fraction::MASKR(1));
return result;
}
}
diff --git a/flang/test/Evaluate/fold-spacing.f90 b/flang/test/Evaluate/fold-spacing.f90
index d802f1770666e..27834da6c2320 100644
--- a/flang/test/Evaluate/fold-spacing.f90
+++ b/flang/test/Evaluate/fold-spacing.f90
@@ -5,6 +5,8 @@ module m
logical, parameter :: test_2 = spacing(-3.0) == scale(1.0, -22)
logical, parameter :: test_3 = spacing(3.0d0) == scale(1.0, -51)
logical, parameter :: test_4 = spacing(0.) == tiny(0.)
+ logical, parameter :: test_5 = spacing(tiny(0.)) == 1.e-45
+ logical, parameter :: test_6 = spacing(8388608.) == 1.
logical, parameter :: test_11 = rrspacing(3.0) == scale(0.75, 24)
logical, parameter :: test_12 = rrspacing(-3.0) == scale(0.75, 24)
logical, parameter :: test_13 = rrspacing(3.0d0) == scale(0.75, 53)
More information about the flang-commits
mailing list