From patchwork Mon Sep 5 15:57:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp239312wrt; Mon, 5 Sep 2022 08:58:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR6XUYu5MDgnwjRP8/URfPGF+NCxBscWUvWEtTD9DAoIlSKWwzWP83s9nmT6jMII8YR5h0Sg X-Received: by 2002:a17:907:2716:b0:73d:cdf9:b08a with SMTP id w22-20020a170907271600b0073dcdf9b08amr35240956ejk.463.1662393487234; Mon, 05 Sep 2022 08:58:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662393487; cv=none; d=google.com; s=arc-20160816; b=i+K4ImfAoJjEKz2HbH7N4AqTxhjTE0APK8PW9hbhpcNd1Ptl8zxJ8lYGCw19I2WhDq wyae/8F5uvg1w4gra776pUb9G83BgN/M0Ev9dApyO/jF2SZUKw1lZRP8K6SJcjyDEI8O DpOU5DxJ1rHDAoYLf6siQJl0PomoLHSI2OtgI0kW3jXb4i3SeY5n3HQeY4raLqv2IZS1 oXGP1XjhfQqR7HHhUdracew/s+XslJ933/X6Th9FPCTSQzgJne5ZEM8WimtISktSVTEb eWmdl0bKPVN7br5iPFAFml1cFyo1mtI34N5tm8cz9e2Jt+VrWhScB626keU8gobFBfa+ Vq+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=OPXUrzxUD2x5BbFf8+U1V/K584LlnCfLcshoTpVMcCc=; b=I8e80X1dqn5cvg6lwhnqyFt3Gnmk7G/QdGxv5gkBiMckbaHqXv0/8lyA3UcPQMiZNZ avh7L3mGFrnwdJruiHAqBAkPvyfDnOYZQzBI6fmDUwKiP7x+7Nvc9dW0kwukbUMF7L6/ A7EsjafYcIUlRB6VaD5LL9rwHdE9r8NTenhyDt9Qx9RHGz+9SChzg06Lwbq/TX2IOroP bcFQbT+ru7EMccIeGFhesn12Na/ytpafxunYiLG0J+iZPD5q348r3a6Sjm7eWHlwEi++ QY8V4kGUT3mARcvEe2Jz97Ks7mrfM6sDVuNXhIJeT9zg+cPcqBcr2Gy8VT40ZHdGsO+r GOZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=d2H4Y42E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qf40-20020a1709077f2800b00730babc11e3si8163593ejc.640.2022.09.05.08.58.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 08:58:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=d2H4Y42E; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 C7F5F3856DC0 for ; Mon, 5 Sep 2022 15:58:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7F5F3856DC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662393480; bh=OPXUrzxUD2x5BbFf8+U1V/K584LlnCfLcshoTpVMcCc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=d2H4Y42EM7XkkuWH1LwPc8glbo7P8BfnLnHHluA3zdFXsq2NnH1Z3rE8Pi+Oishl+ PFRdiyXNr3VmQ1jcFVDCDWVz3L4fDJc8pBtWyp5kJlOfnFfjYzjUnEECgwFuWcZOQA JSqDeYJqawwK7RKYKAnaQmWajDm5SAQlg046o/RU= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 6D69F3858CDA for ; Mon, 5 Sep 2022 15:57:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D69F3858CDA 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-317-aEJsJhQjPs-wAFvfgkNmbg-1; Mon, 05 Sep 2022 11:57:14 -0400 X-MC-Unique: aEJsJhQjPs-wAFvfgkNmbg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD45829AB3FB for ; Mon, 5 Sep 2022 15:57:13 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65E3C492C3B; Mon, 5 Sep 2022 15:57:13 +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 285FvAAD3420418 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 5 Sep 2022 17:57:11 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 285FvA7Q3420417; Mon, 5 Sep 2022 17:57:10 +0200 To: GCC patches Subject: [COMMITTED] [PR middle-end/106824] Do not ICE when updating a NAN to a non-NAN. Date: Mon, 5 Sep 2022 17:57:08 +0200 Message-Id: <20220905155708.3420282-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 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?1743145913037042272?= X-GMAIL-MSGID: =?utf-8?q?1743145913037042272?= Updating a definite NAN to a definitely not NAN was an assertion failure, but it turns out we can have such a scenario while attempting to thread an impossible path. This patch updates the range to undefined. What happens in the testcase is that we are trying to thread path that starts like this: [local count: 81335936906]: SR.30_3 = Nan; goto ; [100.00%] [local count: 108447915740]: # SR.30_25 = PHI plus_33 = SR.30_25; w1$value__13 = f_distance$D2421$value__1; w2$value__14 = plus_33; if (w1$value__13 == w2$value__14) goto ; [50.00%] else goto ; [50.00%] On the path, SR.30_25 is NAN, which ultimately makes w2$value__14 a NAN. This means that the 7->8 is impossible on the path. On the true arm (foperator_equal::op1_range) we are asserting that op1 (w1$value__13) is a !NAN because for the == conditional to succeed, neither operand can be a NAN. But...we know that operand 2 is a NAN. This is an impossible scenario. We are ICEing because frange::set_nan() sees the NAN and the desire to set the NAN flag to NO. The correct thing to do is to set the range to undefined, which is basically unreachable, and will cause all the right things to happen. For that matter, the threader will see that an UNDEFINED range was calculated in the path and abort trying to investigate paths in that direction. Tested on x86-64 Linux with regstrap as well as mpfr tests. PR middle-end/106824 gcc/ChangeLog: * value-range.cc (frange::set_nan): Set undefined when updating a NAN to a non-NAN. gcc/testsuite/ChangeLog: * g++.dg/pr106824.C: New test. --- gcc/testsuite/g++.dg/pr106824.C | 76 +++++++++++++++++++++++++++++++++ gcc/value-range.cc | 12 +++++- 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr106824.C diff --git a/gcc/testsuite/g++.dg/pr106824.C b/gcc/testsuite/g++.dg/pr106824.C new file mode 100644 index 00000000000..bd80be0dfaa --- /dev/null +++ b/gcc/testsuite/g++.dg/pr106824.C @@ -0,0 +1,76 @@ +// { dg-do compile } +// { dg-options "-O2 -w -std=c++11" } + +using int32 = int; +int ShortestPath_distance; +struct FloatWeightTpl { + FloatWeightTpl(float f) : value_(f) {} + float Value() { return value_; } + float value_; +}; +template bool operator!=(FloatWeightTpl w1, T w2) { + bool __trans_tmp_2; + FloatWeightTpl __trans_tmp_3 = w1; + __trans_tmp_2 = __trans_tmp_3.Value() == w2.Value(); + return __trans_tmp_2; +} +struct TropicalWeightTpl : FloatWeightTpl { + TropicalWeightTpl(float f) : FloatWeightTpl(f) {} + static TropicalWeightTpl Zero(); + static TropicalWeightTpl NoWeight() { + float __trans_tmp_5 = __builtin_nanf(""); + return __trans_tmp_5; + } + bool Member() { return value_; } +}; +TropicalWeightTpl Plus(TropicalWeightTpl w1, TropicalWeightTpl &w2) { + return w1.Member() || w2.Member() ? TropicalWeightTpl::NoWeight() : w2.Value() ? : w2; +} +TropicalWeightTpl Times(); +struct ArcTpl { + using Weight = TropicalWeightTpl; +}; +template struct ShortestPathOptions { + ShortestPathOptions(int, int, int32, bool, bool); +}; +template +void SingleShortestPath(ShortestPathOptions) { + using Weight = typename Arc::Weight; + auto f_distance = Weight::Zero(); + while (!0) { + TropicalWeightTpl __trans_tmp_1 = Times(), + plus = Plus(f_distance, __trans_tmp_1); + if (f_distance != plus) + f_distance = plus; + } +} +template +void ShortestPath(int, int *, int *, + ShortestPathOptions opts) { + SingleShortestPath(opts); +} +struct ShortestDistanceOptions { + float delta; +}; +struct Trans_NS_script_ShortestPathOptions : ShortestDistanceOptions { + int32 nshortest; + bool unique; +}; +namespace internal { +template +void ShortestPath(int ifst, int *ofst, int *distance, + Trans_NS_script_ShortestPathOptions opts) { + using ArcFilter = int; + ShortestPathOptions sopts(opts.nshortest, opts.unique, + false, opts.delta, 0); + ShortestPath(ifst, ofst, distance, sopts); +} +int ShortestPath_ifst; +int ShortestPath_ofst; +Trans_NS_script_ShortestPathOptions ShortestPath_opts; +void ShortestPath() { + using StateId = int; + ShortestPath(ShortestPath_ifst, &ShortestPath_ofst, + &ShortestPath_distance, ShortestPath_opts); +} +} // namespace internal diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 9c561415971..c3f668a811a 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -274,13 +274,21 @@ frange::set_nan (fp_prop::kind k) { if (k == fp_prop::YES) { + if (get_nan ().no_p ()) + { + set_undefined (); + return; + } gcc_checking_assert (!undefined_p ()); *this = frange_nan (m_type); return; } - // Setting NO on an obviously NAN range is nonsensical. - gcc_checking_assert (k != fp_prop::NO || !real_isnan (&m_min)); + if (k == fp_prop::NO && get_nan ().yes_p ()) + { + set_undefined (); + return; + } // Setting VARYING on an obviously NAN range is a no-op. if (k == fp_prop::VARYING && real_isnan (&m_min))