diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index 462447ba250a4d140c0f068000cbfb090bd7b08b..b57701f0ea102bf1d9e4bb792681d0d176c9ec8b 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -276,13 +276,20 @@ frange_storage_slot::get_frange (frange &r, tree type) const return; } - // Use the constructor because it will canonicalize the range. + // We use the constructor to create the new range instead of writing + // out the bits into the frange directly, because the global range + // being read may be being inlined into a function with different + // restrictions as when it was originally written. We want to make + // sure the resulting range is canonicalized correctly for the new + // consumer. r = frange (type, m_min, m_max, m_kind); // The constructor will set the NAN bits for HONOR_NANS, but we must // make sure to set the NAN sign if known. if (HONOR_NANS (type) && (m_pos_nan ^ m_neg_nan) == 1) r.update_nan (m_neg_nan); + else if (!m_pos_nan && !m_neg_nan) + r.clear_nan (); } bool diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 859c7fb4af9877870ec59a7599ec13ac61eec37c..852ac09f2c46323d7eae7a7b9ff4331747301594 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -4051,6 +4051,15 @@ range_tests_floats () ASSERT_TRUE (real_isinf (&r0.lower_bound (), true)); ASSERT_TRUE (real_isinf (&r0.upper_bound (), true)); } + + // Test that reading back a global range yields the same result as + // what we wrote into it. + tree ssa = make_temp_ssa_name (float_type_node, NULL, "blah"); + r0.set_varying (float_type_node); + r0.clear_nan (); + set_range_info (ssa, r0); + get_global_range_query ()->range_of_expr (r1, ssa); + ASSERT_EQ (r0, r1); } // Run floating range tests for various combinations of NAN and INF