From patchwork Wed Sep 21 11:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 57843 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A2E13858413 for ; Wed, 21 Sep 2022 11:33:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A2E13858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663760030; bh=ArmuwxV9h9KD4d65X44DH1cGTIoUrUmpw/8liwvwae0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ihdCR5nRNd7jxpDmjqwLe0obb9TD0+AIbfSjSs7WsW4hJr7K5ofxmtDODDnxKgmN5 N8me3YltMb01yeWclCruTZPl8znj2/rh551JeLyQmWUeiEASO6Cm2nUSIQ5yCZBnCq MVH3TxpKFhecejEGcdKCVvxXAkVmsyZKb4+sPvoo= 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 2F0C73858C52 for ; Wed, 21 Sep 2022 11:33:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F0C73858C52 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-498-jQrIZphdN_i8arwCqx0cog-1; Wed, 21 Sep 2022 07:33:16 -0400 X-MC-Unique: jQrIZphdN_i8arwCqx0cog-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80A83101A5DC; Wed, 21 Sep 2022 11:33:16 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22F9649BB63; Wed, 21 Sep 2022 11:33: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 28LBXD1a2173329 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 21 Sep 2022 13:33:13 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28LBXDuf2173328; Wed, 21 Sep 2022 13:33:13 +0200 To: GCC patches Subject: [COMMITTED] [PR106967] Set known NANs to undefined for flag_finite_math_only. Date: Wed, 21 Sep 2022 13:30:40 +0200 Message-Id: <20220921113039.2173181-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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 Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Richard, this is what you suggested. Thanks. Explicit NANs in the IL can be treated as undefined for flag_finite_math_only. This causes all the right things to happen wrt threading, folding, etc. It also saves us special casing throughout. It occurs to me that we should do something similar for infinities for -ffinite-math-only. That is, drop them to the min/max representable numbers, and adjust everything (including VARYING endpoints) accordingly. Furthermore, we should saturate to min/max representable in the setter, so (upcoming) binary operators don't have to worry about going over min/max. Sigh...floating point... the gift that keeps on giving. gcc/ChangeLog: * value-range.cc (frange::set): Set known NANs to undefined for flag_finite_math_only. --- gcc/value-range.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 505eb9211a7..7e8028eced2 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -313,8 +313,13 @@ frange::set (tree min, tree max, value_range_kind kind) gcc_checking_assert (real_identical (TREE_REAL_CST_PTR (min), TREE_REAL_CST_PTR (max))); tree type = TREE_TYPE (min); - bool sign = real_isneg (TREE_REAL_CST_PTR (min)); - set_nan (type, sign); + if (HONOR_NANS (type)) + { + bool sign = real_isneg (TREE_REAL_CST_PTR (min)); + set_nan (type, sign); + } + else + set_undefined (); return; }