diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2022-09-17 10:17:13 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2022-09-20 07:15:53 +0200 |
commit | 2b61ed838c7f3f4bf54d4530c0f053b420623beb (patch) | |
tree | fe47a01ed74f10a60e11a5514e3f1040125648a1 /gcc | |
parent | 041812f584a1c82f1255bd96f3503493bd9fb127 (diff) | |
download | gcc-2b61ed838c7f3f4bf54d4530c0f053b420623beb.zip gcc-2b61ed838c7f3f4bf54d4530c0f053b420623beb.tar.gz gcc-2b61ed838c7f3f4bf54d4530c0f053b420623beb.tar.bz2 |
frange: flush denormals to zero
For some architectures (or for -funsafe-math-optimizations) we may
flush denormals to zero, in which case we need to be careful to
extend the ranges to the appropriate zero. This patch does exactly that.
For a range of [x, -DENORMAL] we flush to [x, -0.0] and for [+DENORMAL, x]
we flush to [+0.0, x].
gcc/ChangeLog:
* value-range.cc (frange::flush_denormals_to_zero): New.
(frange::set): Call flush_denormals_to_zero.
* value-range.h (class frange): Add flush_denormals_to_zero.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/value-range.cc | 23 | ||||
-rw-r--r-- | gcc/value-range.h | 1 |
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 67d5d7f..a8e3bb3 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -267,6 +267,26 @@ tree_compare (tree_code code, tree op1, tree op2) return !integer_zerop (fold_build2 (code, integer_type_node, op1, op2)); } +// Flush denormal endpoints to the appropriate 0.0. + +void +frange::flush_denormals_to_zero () +{ + if (undefined_p () || known_isnan ()) + return; + + // Flush [x, -DENORMAL] to [x, -0.0]. + if (real_isdenormal (&m_max) && real_isneg (&m_max)) + { + m_max = dconst0; + if (HONOR_SIGNED_ZEROS (m_type)) + m_max.sign = 1; + } + // Flush [+DENORMAL, x] to [+0.0, x]. + if (real_isdenormal (&m_min) && !real_isneg (&m_min)) + m_min = dconst0; +} + // Setter for franges. void @@ -317,6 +337,9 @@ frange::set (tree min, tree max, value_range_kind kind) gcc_checking_assert (tree_compare (LE_EXPR, min, max)); normalize_kind (); + + flush_denormals_to_zero (); + if (flag_checking) verify_range (); } diff --git a/gcc/value-range.h b/gcc/value-range.h index 3a401f3..795b1f0 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -327,6 +327,7 @@ private: bool union_nans (const frange &); bool intersect_nans (const frange &); bool combine_zeros (const frange &, bool union_p); + void flush_denormals_to_zero (); tree m_type; REAL_VALUE_TYPE m_min; |