From patchwork Sat Sep 3 15:36: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: 949 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1229484wro; Sat, 3 Sep 2022 08:36:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR60pu3UxRzVB+Vlg0ClV0aJ5BzRABpMZuDiWif1KZdQtPGgw58jP/MT8ZBM+VwYfkI80jYh X-Received: by 2002:a05:6402:42d4:b0:443:4b8:8cba with SMTP id i20-20020a05640242d400b0044304b88cbamr37050953edc.3.1662219419710; Sat, 03 Sep 2022 08:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662219419; cv=none; d=google.com; s=arc-20160816; b=Ndi7xTlBmuPLPkxZ838HwK56YhWAXO8YyqQW4pDrrX6doH+FBPpbTCgiaenfeK+QCS 6UGem4qzZrC98oe5XA2jvQ0jyf/IfkRKU+Tnmz863IjJ97G95Lh1uCzX6wfhUeJu2fnT UF8847Av3TskEDpRAYvs6jWQ/WJH8wMt361IfcULSD5VUXChfUzTLa+J7aFDDA9Jm0fc GDF9AmucdleYra6LjugVQFkFI5L6IMaJS4pX0SqY02mJTd6fyRexmrV6Zszz9uLhqeMl c9dhyY0YwVggIqym3PKAV1pqJjP7qCNQMlGObXYG6l6GDsGMW6JwOtEwSF/xSIUNFt+f R/VA== 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=opnNAKuVPgMR5C/QGAVHEVhVobCnERsvpEzz3d77RP4=; b=M4BQgtM624N01YoWVyiC0Tyjjd3fupvOXq8CND9K+hClyBr1oX7pp64NNAeK4ouXXU IAzhloQ0sP/Jqq31CvDAt1NZfpjVGP0bGyE45+u4L30vr/Ki0ORyt84QCN2tW16x3k7O ZZ6tLGjHiC4YvSPOXC/hVGb+cmrAw+Ip89hwm0m8+0yUgmvikaWPn8fnsF072ZmvgkRJ 7bSFVPJmauN7YhnEsPY/cgyIlGayy6KCuO3itYJZ+/ImAAzrsvmfJeNa1YL+jsOHbk5X G1LuHWCl0y2MiXtjETEINlb5nG9NxJ2fOBVGCtgT5VrgGMXwSJFwerZAKM72NRq222h6 MRHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ok3DAC+g; 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 g12-20020a056402090c00b00446eaa6faddsi4706311edz.445.2022.09.03.08.36.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Sep 2022 08:36:59 -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=Ok3DAC+g; 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 847813858CDB for ; Sat, 3 Sep 2022 15:36:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 847813858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662219418; bh=opnNAKuVPgMR5C/QGAVHEVhVobCnERsvpEzz3d77RP4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ok3DAC+gEfGqUqHOGKFY/oZi/tZNoAlTF67AZEZ5Da4IQZMt5b2sfcUBgpy5JQUft FUK6eFzvs0gYnDyBuxRYkuE0d7Jocix0+uKPbpnXS/1zr2GtyGKXTi05/gPH/GTlKG syqcLhW08VQbphK73GHGhQsa3nzwKyfyxyLdII6U= 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 E797A3858CDB for ; Sat, 3 Sep 2022 15:36:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E797A3858CDB Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-595-8tgXDBpjMCG0dZ1jZzkTkQ-1; Sat, 03 Sep 2022 11:36:14 -0400 X-MC-Unique: 8tgXDBpjMCG0dZ1jZzkTkQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3713D85A589 for ; Sat, 3 Sep 2022 15:36:14 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CDD482026D4C; Sat, 3 Sep 2022 15:36: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 283FaB1A3043402 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 3 Sep 2022 17:36:11 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 283FaBNt3043401; Sat, 3 Sep 2022 17:36:11 +0200 To: GCC patches Subject: [COMMITTED] [PR 106819] NANs can never be a singleton Date: Sat, 3 Sep 2022 17:36:08 +0200 Message-Id: <20220903153608.3043385-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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?1742963390194590683?= X-GMAIL-MSGID: =?utf-8?q?1742963390194590683?= Possible NANs can never be a singleton, so they will never be propagated. This was the intent, and then the signed zero code crept in, and was mistakenly checked before the NAN. PR 106819 gcc/ChangeLog: * value-range.cc (frange::singleton_p): Move NAN check to the top. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr106819.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr106819.c | 24 ++++++++++++++++++++++++ gcc/value-range.cc | 9 ++++----- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr106819.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr106819.c b/gcc/testsuite/gcc.dg/tree-ssa/pr106819.c new file mode 100644 index 00000000000..1272d4b5805 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr106819.c @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp-details" } + +static int isNaN(double x) +{ + return x != x; +} + +static double opCmpProper(int lhs, double rhs) +{ + return lhs < rhs ? -1.0 + : lhs > rhs ? 1.0 + : lhs == rhs ? 0.0 + : __builtin_nan(""); +} + +int main() +{ + if (!isNaN(opCmpProper(41, __builtin_nan("")))) + __builtin_abort(); + return 0; +} + +// { dg-final {scan-tree-dump-not "Folds to: 0.0" "evrp" } } diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 6fd6e3b745c..a1c29f7bd0b 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -632,6 +632,10 @@ frange::singleton_p (tree *result) const { if (m_kind == VR_RANGE && real_identical (&m_min, &m_max)) { + // Return false for any singleton that may be a NAN. + if (HONOR_NANS (m_type) && !get_nan ().no_p ()) + return false; + // Return the appropriate zero if known. if (HONOR_SIGNED_ZEROS (m_type) && zero_p ()) { @@ -649,11 +653,6 @@ frange::singleton_p (tree *result) const } return false; } - - // Return false for any singleton that may be a NAN. - if (HONOR_NANS (m_type) && !get_nan ().no_p ()) - return false; - if (result) *result = build_real (m_type, m_min); return true;