From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 221593857403 for ; Tue, 11 Oct 2022 13:51:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 221593857403 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665496314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rSPYiEfM6PIfuGkEnDY2RKap/KCt6M3AbPERBbSdugM=; b=O/N2RQeRpTc6JJaI3cAzUdpkR57eGKzgoNdQnMIj0Q8RWHF3bnlfPc20oUEXZLHeH0/p4Q kI6+kD2cWFuaYnb1AAYJ+CkTo2G0EjlXYVZbOFdnxuAhJLnK8AFHu3jW2TN8sTSmyz7JRC iWv2kIiIPBU8+uT5Iv1laME4/LfjjVM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-139-l3KMgeWSNWKklaTPxku8SA-1; Tue, 11 Oct 2022 09:51:53 -0400 X-MC-Unique: l3KMgeWSNWKklaTPxku8SA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39DC63833283 for ; Tue, 11 Oct 2022 13:51:53 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.162]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D24C0140EBF5; Tue, 11 Oct 2022 13:51:52 +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 29BDpoHD369678 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 11 Oct 2022 15:51:50 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29BDpomw369677; Tue, 11 Oct 2022 15:51:50 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] Share common ordered comparison code with UN*_EXPR. Date: Tue, 11 Oct 2022 15:51:34 +0200 Message-Id: <20221011135136.369644-2-aldyh@redhat.com> In-Reply-To: <20221011135136.369644-1-aldyh@redhat.com> References: <20221011135136.369644-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.0 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,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 List-Id: Most unordered comparisons can use the result from the ordered version, if the operands are known not to be NAN or if the result is true. gcc/ChangeLog: * range-op-float.cc (class foperator_unordered_lt): New. (class foperator_relop_unknown): Remove (class foperator_unordered_le): New. (class foperator_unordered_gt): New. (class foperator_unordered_ge): New. (class foperator_unordered_equal): New. (floating_op_table::floating_op_table): Replace all UN_EXPR entries with their appropriate fop_unordered_* counterpart. --- gcc/range-op-float.cc | 140 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 128 insertions(+), 12 deletions(-) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 3cf117d8931..8dd4bcc70c0 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1132,24 +1132,140 @@ foperator_ordered::op1_range (frange &r, tree type, return true; } -// Placeholder for unimplemented relational operators. +class foperator_unordered_lt : public range_operator_float +{ + using range_operator_float::fold_range; +public: + bool fold_range (irange &r, tree type, + const frange &op1, const frange &op2, + relation_kind rel) const final override + { + if (op1.known_isnan () || op2.known_isnan ()) + { + r = range_true (type); + return true; + } + if (!fop_lt.fold_range (r, type, op1, op2, rel)) + return false; + // The result is the same as the ordered version when the + // comparison is true or when the operands cannot be NANs. + if (finite_operands_p (op1, op2) || r == range_true (type)) + return true; + else + { + r = range_true_and_false (type); + return true; + } + } +} fop_unordered_lt; -class foperator_relop_unknown : public range_operator_float +class foperator_unordered_le : public range_operator_float { using range_operator_float::fold_range; +public: + bool fold_range (irange &r, tree type, + const frange &op1, const frange &op2, + relation_kind rel) const final override + { + if (op1.known_isnan () || op2.known_isnan ()) + { + r = range_true (type); + return true; + } + if (!fop_le.fold_range (r, type, op1, op2, rel)) + return false; + // The result is the same as the ordered version when the + // comparison is true or when the operands cannot be NANs. + if (finite_operands_p (op1, op2) || r == range_true (type)) + return true; + else + { + r = range_true_and_false (type); + return true; + } + } +} fop_unordered_le; +class foperator_unordered_gt : public range_operator_float +{ + using range_operator_float::fold_range; public: bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, - relation_kind) const final override + relation_kind rel) const final override { if (op1.known_isnan () || op2.known_isnan ()) - r = range_true (type); + { + r = range_true (type); + return true; + } + if (!fop_gt.fold_range (r, type, op1, op2, rel)) + return false; + // The result is the same as the ordered version when the + // comparison is true or when the operands cannot be NANs. + if (finite_operands_p (op1, op2) || r == range_true (type)) + return true; else - r.set_varying (type); - return true; + { + r = range_true_and_false (type); + return true; + } + } +} fop_unordered_gt; + +class foperator_unordered_ge : public range_operator_float +{ + using range_operator_float::fold_range; +public: + bool fold_range (irange &r, tree type, + const frange &op1, const frange &op2, + relation_kind rel) const final override + { + if (op1.known_isnan () || op2.known_isnan ()) + { + r = range_true (type); + return true; + } + if (!fop_ge.fold_range (r, type, op1, op2, rel)) + return false; + // The result is the same as the ordered version when the + // comparison is true or when the operands cannot be NANs. + if (finite_operands_p (op1, op2) || r == range_true (type)) + return true; + else + { + r = range_true_and_false (type); + return true; + } + } +} fop_unordered_ge; + +class foperator_unordered_equal : public range_operator_float +{ + using range_operator_float::fold_range; +public: + bool fold_range (irange &r, tree type, + const frange &op1, const frange &op2, + relation_kind rel) const final override + { + if (op1.known_isnan () || op2.known_isnan ()) + { + r = range_true (type); + return true; + } + if (!fop_equal.fold_range (r, type, op1, op2, rel)) + return false; + // The result is the same as the ordered version when the + // comparison is true or when the operands cannot be NANs. + if (finite_operands_p (op1, op2) || r == range_true (type)) + return true; + else + { + r = range_true_and_false (type); + return true; + } } -} fop_unordered_relop_unknown; +} fop_unordered_equal; // Instantiate a range_op_table for floating point operations. @@ -1174,11 +1290,11 @@ floating_op_table::floating_op_table () set (LE_EXPR, fop_le); set (GT_EXPR, fop_gt); set (GE_EXPR, fop_ge); - set (UNLE_EXPR, fop_unordered_relop_unknown); - set (UNLT_EXPR, fop_unordered_relop_unknown); - set (UNGE_EXPR, fop_unordered_relop_unknown); - set (UNGT_EXPR, fop_unordered_relop_unknown); - set (UNEQ_EXPR, fop_unordered_relop_unknown); + set (UNLE_EXPR, fop_unordered_le); + set (UNLT_EXPR, fop_unordered_lt); + set (UNGE_EXPR, fop_unordered_ge); + set (UNGT_EXPR, fop_unordered_gt); + set (UNEQ_EXPR, fop_unordered_equal); set (ORDERED_EXPR, fop_ordered); set (UNORDERED_EXPR, fop_unordered); } -- 2.37.3