From patchwork Mon Sep 19 07:59:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1294 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp849870wrt; Mon, 19 Sep 2022 01:01:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SbX4QlyRraWpBIgGtF3kiqYBP0wWPm24KH49/1pC+qI/MaMKs5dJ0hA3L6Z2wftd0w2bD X-Received: by 2002:a17:906:974d:b0:780:2c07:7617 with SMTP id o13-20020a170906974d00b007802c077617mr12286510ejy.707.1663574470780; Mon, 19 Sep 2022 01:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663574470; cv=none; d=google.com; s=arc-20160816; b=BTFJyAPwg/5j2mHiduc6DfkVYf+1g/VqGmDNkSgid4finPMXxv8E5scqtA9oBbuY8I 9qM5QHXS7C2WEYuE/461hju41cZER6JqhH5bb0iS9bXY3Xt9w2qeYchOvb/nmUwIQWIB tmPIbvkQd4SP3wz8+nUk7o+QPNrr4uxTagCh+HUg/LHhbKpX+GTqsedXR5Ph9tfz8UZC Y5w+8VO92D3LAxWppzJzkNlgiPrtyq769Mq0MZLnlyAy/BA2oks75M3gKlS7sDBoEEQ4 U6c80klq0+fau+jTloEhXHrbHak+5rPWY7iA+GvTuL2tEdy9Xjsl1oSuPqO7M64S6hXg 48wA== 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=MEaMqcUiYJtVkNuyl2Is79FfNpf9bBu9NnBl1Ww+4Us=; b=YCnqPei+V6xKeR0d+F7zJzcwgrmbfIsGjC9o6HfGHO6Edhxz80x87KARpX5YpzIRAC DzwSW4oYWVSafaKzlrs56FPAc3Hql2NE2iGNoZcD8iRE3s4YW+jDkPmWQFKkWpUBke49 BH3V8BmzUE68KJVuuTHAovUBJeHZB/1HjytOeOVrtW0s1j4KuLXAhX7CeZ8vJrMsKyP3 jVdbQuDefhJ5d1zXSW/cLxQxllqohVfaqjONEiE/dwehIBNiBy1yuc8EIcMJlCDIobdu MtE9n35Aj1pXbU8OmN39UrE16kXdzV5REHZM/PMfY5TQtYfEZOEb30MbBOkSwNal+pLl YlyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PSWMJS94; 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 h16-20020a05640250d000b00447eb58b921si10370160edb.38.2022.09.19.01.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 01:01:10 -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=PSWMJS94; 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 D32843858CDA for ; Mon, 19 Sep 2022 08:01:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D32843858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663574469; bh=MEaMqcUiYJtVkNuyl2Is79FfNpf9bBu9NnBl1Ww+4Us=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=PSWMJS94XSamTo3s3ve+pFUpxmw1PdhOWFSsE2nF9kRBsxI587W+1Guoi6XoLjyX6 ZwjFiRIuiyrvYAB5NwXnOxgn5YhN5IN8WWbYhwSsqBFgOpmUSBfOEMTtbcLRD4kXy0 Qiv+vAJsC9aU7N1KyvthcKG42F9xXTtdyIXoLS6M= 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 89B3638582A5 for ; Mon, 19 Sep 2022 07:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89B3638582A5 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-505-kH1CfakgMc2bxiO1uSC_yw-1; Mon, 19 Sep 2022 03:59:16 -0400 X-MC-Unique: kH1CfakgMc2bxiO1uSC_yw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78B308027EA; Mon, 19 Sep 2022 07:59:16 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEEAE40C6EC2; Mon, 19 Sep 2022 07:59:15 +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 28J7xAHR1798312 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 19 Sep 2022 09:59:10 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28J7xA5M1798311; Mon, 19 Sep 2022 09:59:10 +0200 To: GCC patches Subject: [PATCH] [PR68097] frange::set_nonnegative should not contain -NAN. Date: Mon, 19 Sep 2022 09:59:01 +0200 Message-Id: <20220919075901.1798294-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 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 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?1744384264569545963?= X-GMAIL-MSGID: =?utf-8?q?1744384264569545963?= ISTM that a specifically nonnegative range should not contain -NAN, otherwise signbit_p() would return false, because we'd be unsure of the sign. Do y'all agree? PR 68097/tree-optimization gcc/ChangeLog: * value-range.cc (frange::set_nonnegative): Set +NAN. (range_tests_signed_zeros): New test. * value-range.h (frange::update_nan): New overload to set NAN sign. --- gcc/value-range.cc | 9 +++++++++ gcc/value-range.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 67d5d7fa90f..e432ec8b525 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -752,6 +752,10 @@ void frange::set_nonnegative (tree type) { set (type, dconst0, dconstinf); + + // Set +NAN as the only possibility. + if (HONOR_NANS (type)) + update_nan (/*sign=*/0); } // Here we copy between any two irange's. The ranges can be legacy or @@ -3800,6 +3804,11 @@ range_tests_signed_zeros () r1.update_nan (); r0.intersect (r1); ASSERT_TRUE (r0.known_isnan ()); + + r0.set_nonnegative (float_type_node); + ASSERT_TRUE (r0.signbit_p (signbit) && !signbit); + if (HONOR_NANS (float_type_node)) + ASSERT_TRUE (r0.maybe_isnan ()); } static void diff --git a/gcc/value-range.h b/gcc/value-range.h index 3a401f3e4e2..5b261d4f46a 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -312,6 +312,7 @@ public: const REAL_VALUE_TYPE &lower_bound () const; const REAL_VALUE_TYPE &upper_bound () const; void update_nan (); + void update_nan (bool sign); void clear_nan (); // fpclassify like API @@ -1098,6 +1099,19 @@ frange::update_nan () verify_range (); } +// Like above, but set the sign of the NAN. + +inline void +frange::update_nan (bool sign) +{ + gcc_checking_assert (!undefined_p ()); + m_pos_nan = !sign; + m_neg_nan = sign; + normalize_kind (); + if (flag_checking) + verify_range (); +} + // Clear the NAN bit and adjust the range. inline void