From patchwork Sun Oct 23 14:56:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 8042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp26019wru; Sun, 23 Oct 2022 07:57:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SYgiZWcdOA/R4M4FvLrpa1XHJNsoaMSSn4ibgrLDFVt52trDoXi48QamgMMD+sLUJrrKu X-Received: by 2002:a17:907:2708:b0:7a6:38d7:5987 with SMTP id w8-20020a170907270800b007a638d75987mr2046852ejk.467.1666537049453; Sun, 23 Oct 2022 07:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666537049; cv=none; d=google.com; s=arc-20160816; b=EqlrPhNsdBxgzakJ1h2uGjUQpxZsbMuMlQkt7CcSD19Dsps+XSMND/WKo8P045CzqB /rUXFt0x4Y2oS6oOL6/oLeVWOkQoZMk6CifFMmKrM30bF5+5k5ROYAfEVmT3p/LwPFqp rzzTJbUODpQ9XLDIbvIXXtsoPE22N7ZdJmSTO+EzAFeaNx1Jo9TvB/GSeaNucxEN7ho7 ++fOK6d74uDxMhDgiWEhh02fxccj8I6XuMYMpH6eheATQLkf9yDuYvoIbCjNmON5eFmd vfJ9yeQN+NMDD4K2t/L/vaVrkHfBMWli61qgquA7LtuXZCtb1yy4DdVCAqFb5WNvHeax jwSw== 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=7ns1FNvXVTVsn7AG1/kspJJZ52vR5xZEoVaCmTprwIk=; b=z7TzZygxl8CIoXY7s1SnzI7O8hgQ3PXylb4+gIiMZTb63K6S6sh2IFGs69YWMLCQLm POIVY5+dm48xwBnfsgG8+qq9ZnHoXkdeywEi6THPe7iM75B/J+w6ayUPGvsaYbOf8N5n 3phRwfuUqIbD3H8fFJXlFfDkruUkXaPqUUru9OmQsir5bcoJbcev32BS3Y7LOi/6aGAj nbIwL0Qpanj1LpZ4c2+SoYFc50Rd/HaCxj8me004D8rGastDWDbICclbFEs6KlfMd1Mg PPQ0T/BCyhDpZFUKvTu6gI1RZ2n/KcAkMrrD+6oPxUlw90M6bJUK51+kYDhgiW0RWdUi 6vDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bfsY8mfu; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q24-20020aa7d458000000b0045d5b83114esi18194539edr.112.2022.10.23.07.57.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 07:57:29 -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=bfsY8mfu; 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 6A6A43858CDA for ; Sun, 23 Oct 2022 14:57:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A6A43858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666537048; bh=7ns1FNvXVTVsn7AG1/kspJJZ52vR5xZEoVaCmTprwIk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bfsY8mfuBir5IG6C9Q/eDcXkdvCes9nYLvkdiJs6jJNdx6rrWV8CGYsrWDnYOl49r LIm4EVvuGIlAEhwYK5Nyt3soDj4GLrcU8e7PebZFi3Gih5N4EdjAGXyIM2QAEpDHze jNSN1Eo9epD5aX4A2rh1JD9R6PEIObFTGUHXWP0A= 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 7E3E23858D1E for ; Sun, 23 Oct 2022 14:56:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7E3E23858D1E 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-348-lnH3vv5dPJiU6qu1C7-t_g-1; Sun, 23 Oct 2022 10:56:40 -0400 X-MC-Unique: lnH3vv5dPJiU6qu1C7-t_g-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 E29C285A583; Sun, 23 Oct 2022 14:56:39 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02BB5492B04; Sun, 23 Oct 2022 14:56:38 +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 29NEua2n501635 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 23 Oct 2022 16:56:36 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29NEuavS501634; Sun, 23 Oct 2022 16:56:36 +0200 To: GCC patches Subject: [PATCH] [PR tree-optimization/107365] Check HONOR_NANS instead of flag_finite_math_only in frange:verify_range. Date: Sun, 23 Oct 2022 16:56:33 +0200 Message-Id: <20221023145633.501586-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 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 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?1747490752962292690?= X-GMAIL-MSGID: =?utf-8?q?1747490752962292690?= [Jakub and other FP experts, would this be OK, or am I missing something?] Vax does not seem to have !flag_finite_math_only, but float_type_node does not HONOR_NANS. The check in frange::verify_range dependend on flag_finite_math_only, which is technically not correct since frange::set_varying() checks HONOR_NANS instead of flag_finite_math_only. I'm actually getting tired of flag_finite_math_only and !flag_finite_math_only discrepancies in the selftests (Vax and rx-elf come to mind). I think we should just test both alternatives in the selftests as in this patch. We could also check flag_finite_math_only=0 with a float_type_node that does not HONOR_NANs, but I have no idea how to twiddle FLOAT_MODE_FORMAT temporarily, and that may be over thinking it. How does this look? PR tree-optimization/107365 gcc/ChangeLog: * value-range.cc (frange::verify_range): Predicate NAN check in VARYING range on HONOR_NANS instead of flag_finite_math_only. (range_tests_floats): Same. (range_tests_floats_various): New. (range_tests): Call range_tests_floats_various. --- gcc/value-range.cc | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index d779e9819e2..d8ee6ec0d0f 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -720,13 +720,13 @@ frange::verify_range () gcc_checking_assert (!m_type); return; case VR_VARYING: - if (flag_finite_math_only) - gcc_checking_assert (!m_pos_nan && !m_neg_nan); - else - gcc_checking_assert (m_pos_nan && m_neg_nan); gcc_checking_assert (m_type); gcc_checking_assert (frange_val_is_min (m_min, m_type)); gcc_checking_assert (frange_val_is_max (m_max, m_type)); + if (HONOR_NANS (m_type)) + gcc_checking_assert (m_pos_nan && m_neg_nan); + else + gcc_checking_assert (!m_pos_nan && !m_neg_nan); return; case VR_RANGE: gcc_checking_assert (m_type); @@ -3957,10 +3957,9 @@ range_tests_floats () // A range of [-INF,+INF] is actually VARYING if no other properties // are set. r0 = frange_float ("-Inf", "+Inf"); - if (r0.maybe_isnan ()) - ASSERT_TRUE (r0.varying_p ()); + ASSERT_TRUE (r0.varying_p ()); // ...unless it has some special property... - if (!flag_finite_math_only) + if (HONOR_NANS (r0.type ())) { r0.clear_nan (); ASSERT_FALSE (r0.varying_p ()); @@ -4041,6 +4040,24 @@ range_tests_floats () } } +// Run floating range tests for various combinations of NAN and INF +// support. + +static void +range_tests_floats_various () +{ + int save_finite_math_only = flag_finite_math_only; + + // Test -ffinite-math-only. + flag_finite_math_only = 1; + range_tests_floats (); + // Test -fno-finite-math-only. + flag_finite_math_only = 0; + range_tests_floats (); + + flag_finite_math_only = save_finite_math_only; +} + void range_tests () { @@ -4049,7 +4066,7 @@ range_tests () range_tests_int_range_max (); range_tests_strict_enum (); range_tests_nonzero_bits (); - range_tests_floats (); + range_tests_floats_various (); range_tests_misc (); }