aboutsummaryrefslogtreecommitdiff
path: root/gcc/range-op-float.cc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2022-08-31 14:41:04 +0200
committerAldy Hernandez <aldyh@redhat.com>2022-09-01 13:19:07 +0200
commite9b0dd2afe7a9e8a3033340dfa26ec606930eef5 (patch)
tree5ba1ceb1e6770c9f6e9de27184b2cfe91741b5e1 /gcc/range-op-float.cc
parent0e1b1222af5e5346df9431df817f2e7dca01bee6 (diff)
downloadgcc-e9b0dd2afe7a9e8a3033340dfa26ec606930eef5.zip
gcc-e9b0dd2afe7a9e8a3033340dfa26ec606930eef5.tar.gz
gcc-e9b0dd2afe7a9e8a3033340dfa26ec606930eef5.tar.bz2
Add signbit property to frange to better model signed zeros.
As discussed here: https://gcc.gnu.org/pipermail/gcc-patches/2022-August/600656.html This adds an frange property to keep track of the sign bit. We keep it updated at all times, but we don't use it make any decisions when !HONOR_SIGNED_ZEROS. With this property we can now query the range for the appropriate sign with frange::get_signbit (). Possible values are yes, no, and unknown. gcc/ChangeLog: * range-op-float.cc (foperator_equal::op1_range): Do not copy sign bit. (foperator_not_equal::op1_range): Same. * value-query.cc (range_query::get_tree_range): Set sign bit. * value-range-pretty-print.cc (vrange_printer::visit): Dump sign bit. * value-range.cc (frange::set_signbit): New. (frange::set): Adjust for sign bit. (frange::normalize_kind): Same. (frange::union_): Remove useless comment. (frange::intersect): Same. (frange::contains_p): Adjust for sign bit. (frange::singleton_p): Same. (frange::verify_range): Same. (range_tests_signbit): New tests. (range_tests_floats): Call range_tests_signbit. * value-range.h (class frange_props): Add signbit (class frange): Same.
Diffstat (limited to 'gcc/range-op-float.cc')
-rw-r--r--gcc/range-op-float.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index c30f2af..2f1af40 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -361,6 +361,9 @@ foperator_equal::op1_range (frange &r, tree type,
case BRS_TRUE:
// If it's true, the result is the same as OP2.
r = op2;
+ // Make sure we don't copy the sign bit if we may have a zero.
+ if (HONOR_SIGNED_ZEROS (type) && r.contains_p (build_zero_cst (type)))
+ r.set_signbit (fp_prop::VARYING);
// The TRUE side of op1 == op2 implies op1 is !NAN.
r.set_nan (fp_prop::NO);
break;
@@ -462,6 +465,9 @@ foperator_not_equal::op1_range (frange &r, tree type,
case BRS_FALSE:
// If it's false, the result is the same as OP2.
r = op2;
+ // Make sure we don't copy the sign bit if we may have a zero.
+ if (HONOR_SIGNED_ZEROS (type) && r.contains_p (build_zero_cst (type)))
+ r.set_signbit (fp_prop::VARYING);
// The FALSE side of op1 != op2 implies op1 is !NAN.
r.set_nan (fp_prop::NO);
break;