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: 10985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1213731wru; Tue, 25 Oct 2022 14:03:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lG7VYdZgWSRs1gITKGsKi19JGiS5dXMeQVnJGAvsZ7ChsdWrPwIURh73UyoChrtitlBNn X-Received: by 2002:a50:cc94:0:b0:460:ce6c:3a64 with SMTP id q20-20020a50cc94000000b00460ce6c3a64mr27160278edi.374.1666731797635; Tue, 25 Oct 2022 14:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666731797; cv=none; d=google.com; s=arc-20160816; b=XWYWWZwY4vCpINoRktek5t7UoyG9SEQk/qfWrEjisWudindU13tB1+vXnr9d7h7nr3 ZxczvjO0kCNFzZInO9Chr4pKkkiVxsPEkoXzeaKBc3tCOJ/ytMN3GHIYSwm7pDT7YdRH IpRAm1U30moA+3+VuRtBBqljPf9MB81kCg0LL/yyd7vNCk+q3NNwWmjOGI1nxEpYzS+H ftBHivJJtClyfKJkayaOoS0VCz9ZuRlBA7UqdXIrqeExHdb9JuDlpn3PwjAwZ/gOPDjd xPJMQtaVVmtsdMEHcYoJSzuwebtn/VvJTwWgv7f0wJtD75dX5d1kr5GgHJUpcnmkAxyb MU7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=FetIeloKHqwNqz3V/j8hFGzj25NeBbo1Q1+Q1VBysWg=; b=D5nkDxS4DUDdCZ+6Fxw1gl0zMGHygMt82VIqo9VYMWQDxkJuOehk/6HUu6uDNTYmXr Lp5X70rrd6EDR2fEjLQMtgW62UpD5VwQFdhbUi25at0avNZy85iZ3vIpb1wGQDnm0kYA C61KjgXMLjkpP3acmrzk+shUyx+RAFmL3xuo7IoSp8izNiSQW2POeikPRivK/Zq2+nUN uSrxKqRMqG77/U7IArWxnWxOy7BOIBLsub9zJE/psBRoH7dK4HAZHTge4FYf4PfOL1+Q dxDYoGYXgjF5ejOn8/szrTPbjeXWJeJW9kPI4IytEetYMdruwagJ84G9VTe2gXylHwdZ lnmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DSgSw5m8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q18-20020a170906771200b007aad0673343si3214024ejm.313.2022.10.25.14.03.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 14:03:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DSgSw5m8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A049F385741E for ; Tue, 25 Oct 2022 21:03:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A049F385741E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666731796; 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=DSgSw5m8k6pcs4Qa52qSjZgfHcPB7xTUr+iBpzO2ptDM1v994Hyqe8ieF7WTFvezc SdV6IU39657CggbgFPm1xC7Ybs3bW9jSi3ympaIonMoPMq+raccJiv/vyFqfdOVO95 jaAb0kRXmequ/5zxqIDDLwIVx6bZ95EZpa6KFpQs= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747694961734082247?= X-GMAIL-MSGID: =?utf-8?q?1747694961734082247?= [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