From patchwork Tue Oct 25 21:01:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 59419 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 15CD9385741E for ; Tue, 25 Oct 2022 21:03:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 15CD9385741E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666731782; bh=FetIeloKHqwNqz3V/j8hFGzj25NeBbo1Q1+Q1VBysWg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=F4rwchGXbgQ793m+mEjyOUhLt9E7S5vrb9HsIZ8v71JY22HgA+XKJUcT2S9GsgpXN RjDDEFPV1Su4Hu70PMzohOsPoHU4e2c/v8vv5ph4p1eAGClHcfqJOt7olClvcrbTUV St0ye+xl3qL4cl4rJbdVsp+DjZaL2JzbHfpjZkIc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 562AC3857421 for ; Tue, 25 Oct 2022 21:02:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 562AC3857421 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-290-tY0kK5ugOh2sU2JZKPSkUQ-1; Tue, 25 Oct 2022 17:02:29 -0400 X-MC-Unique: tY0kK5ugOh2sU2JZKPSkUQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6DC963C01D8F; Tue, 25 Oct 2022 21:02:24 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C50692166B2A; Tue, 25 Oct 2022 21:02:16 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 29PL2DTg125263 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 25 Oct 2022 23:02:13 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29PL2DZ5125262; Tue, 25 Oct 2022 23:02:13 +0200 To: Richard Biener Subject: [PATCH] [PR tree-optimization/107394] Canonicalize global franges as they are read back. Date: Tue, 25 Oct 2022 23:01:40 +0200 Message-Id: <20221025210140.125230-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: Jakub Jelinek , GCC patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" [Richi/Jakub/FP experts, does this sound like the right solution, or am I missing some subtle IPA/inlining issue?] 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. --- gcc/testsuite/gcc.dg/tree-ssa/pr107394.c | 22 ++++++++++++++++++++++ gcc/value-range-storage.cc | 18 +++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107394.c 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..b660102e064 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -261,17 +261,13 @@ 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 (); + // 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