From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id D00EA384C00B; Thu, 27 Oct 2022 09:40:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D00EA384C00B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666863650; bh=OJ6DwmwDATt9ggpX6zwHyEYzZyUb4vxitI2VzHcnkQw=; h=From:To:Subject:Date:From; b=cIbFGdX+9v8kRPA11VT8PR0IFX6dw3CjBsve2P01vJ73j6++cML4F2XJwDf5lIPja 6J//knRMPJIzc6aLKirqwxCKYTG3bPwIajBm4izFButSD9lcSSpNAUPBHDtV7+Jp6Z AQLGuTDjrMvVqRkGqUo9YmweiO8CGLKF2hCvIAwk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3525] [PR tree-optimization/107394] Canonicalize global franges as they are read back. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 9119431bc1563217c7c770035b0456d1e2bc596d X-Git-Newrev: 2b1fb720818a85d5c893ce65d140add40debf2ff Message-Id: <20221027094050.D00EA384C00B@sourceware.org> Date: Thu, 27 Oct 2022 09:40:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2b1fb720818a85d5c893ce65d140add40debf2ff commit r13-3525-g2b1fb720818a85d5c893ce65d140add40debf2ff Author: Aldy Hernandez Date: Tue Oct 25 22:44:51 2022 +0200 [PR tree-optimization/107394] Canonicalize global franges as they are read back. The problem here is that we're inlining a global range with NANs into a function that has been tagged with __attribute__((optimize ("-ffinite-math-only"))). As the global range is copied from SSA_NAME_RANGE_INFO, its NAN bits are copied, which then cause frange::verify_range() to fail a sanity check making sure no NANs creep in when !HONOR_NANS. I think what we should do is nuke the NAN bits as we're restoring the global range. For that matter, if we use the frange constructor, everything except that NAN sign will be done automatically, including dropping INFs to the min/max representable range when appropriate. PR tree-optimization/107394 gcc/ChangeLog: * value-range-storage.cc (frange_storage_slot::get_frange): Use frange constructor. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107394.c: New test. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/pr107394.c | 22 +++++++++++++++++++++ gcc/value-range-storage.cc | 33 +++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107394.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107394.c new file mode 100644 index 00000000000..0e1e5ac40ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107394.c @@ -0,0 +1,22 @@ +// { dg-do compile } +// { dg-options "-O2" } + +static double +quux (double x) +{ + return __builtin_fabs (x); +} + +__attribute__ ((flatten, optimize ("-ffinite-math-only"))) static int +bar (int *p) +{ + *p = quux (0.0); + + return 0; +} + +void +foo (int *p) +{ + (void) bar (p); +} diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index 6e054622830..462447ba250 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -261,17 +261,28 @@ frange_storage_slot::get_frange (frange &r, tree type) const { gcc_checking_assert (r.supports_type_p (type)); - r.set_undefined (); - r.m_kind = m_kind; - r.m_type = type; - r.m_min = m_min; - r.m_max = m_max; - r.m_pos_nan = m_pos_nan; - r.m_neg_nan = m_neg_nan; - r.normalize_kind (); - - if (flag_checking) - r.verify_range (); + // Handle explicit NANs. + if (m_kind == VR_NAN) + { + if (HONOR_NANS (type)) + { + if (m_pos_nan && m_neg_nan) + r.set_nan (type); + else + r.set_nan (type, m_neg_nan); + } + else + r.set_undefined (); + return; + } + + // Use the constructor because it will canonicalize the range. + 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); } bool