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: 1693502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=aO9Hbnzn; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MwLs06JkQz23kt for ; Mon, 24 Oct 2022 01:57:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 516DB3858407 for ; Sun, 23 Oct 2022 14:57:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 516DB3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666537024; 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=aO9HbnznUHOmHvsABaEJqDTQLeSt5BvdEi7TfYfEPtsKdBAfF9bZBDxT1Qd2LV5rm 57Z4zawsV6CVFLCy8PwF2yCwQKSWsd1HBts66jcbFvZ6fETM2/9Q73pQeQJGIxeyNh +RZOoFMJCJkLHJCVT3d/U6cOmkvN/3ZNlyb5YfLs= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" [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 (); }