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 C2EE93858D38 for ; Wed, 12 Oct 2022 18:28:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C2EE93858D38 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=1665599312; 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; bh=b4Rj4B1A8vabyZtbK7beFw/7rFA2/sKacIOKqrdVhQ0=; b=TTB3BxWbIwfPetKHJK8PplTcdTRGeBrVR7S8gg9kh9VlOJ9cPwRPROIJq/ezHQvlJNcfkS SvrCyrqicmx+1R0PzFROiumlwkYWfbqmWWr1ToXC8QFbKKZZMP3btKPXJ/KvqHIOnEZHmX txE9HbqNfrZUwqQsWorzxlPcDPcxGJE= 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-401-y4mvoJ0aMRG6LH6aRwenag-1; Wed, 12 Oct 2022 14:28:31 -0400 X-MC-Unique: y4mvoJ0aMRG6LH6aRwenag-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F253B3C025B6 for ; Wed, 12 Oct 2022 18:28:30 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.22.11.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A59FE208485A; Wed, 12 Oct 2022 18:28:30 +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 29CISSA6424156 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Oct 2022 20:28:28 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29CISR0c424155; Wed, 12 Oct 2022 20:28:27 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] Add range-op entry for floating point NEGATE_EXPR. Date: Wed, 12 Oct 2022 20:27:49 +0200 Message-Id: <20221012182748.424078-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: Handling negate is pretty easy, as all you have to do is flip the sign bit, even for NANs. gcc/ChangeLog: * range-op-float.cc (class foperator_negate): New. (floating_op_table::floating_op_table): Add NEGATE_EXPR (range_op_float_tests): Add negate tests. --- gcc/range-op-float.cc | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 22b7418c197..229b9d23351 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1132,6 +1132,52 @@ foperator_ordered::op1_range (frange &r, tree type, return true; } +class foperator_negate : public range_operator_float +{ + using range_operator_float::fold_range; + using range_operator_float::op1_range; +public: + bool fold_range (frange &r, tree type, + const frange &op1, const frange &op2, + relation_kind = VREL_VARYING) const final override + { + if (empty_range_varying (r, type, op1, op2)) + return true; + if (op1.known_isnan ()) + { + bool sign; + if (op1.nan_signbit_p (sign)) + r.set_nan (type, !sign); + else + r.set_nan (type); + return true; + } + + REAL_VALUE_TYPE lh_lb = op1.lower_bound (); + REAL_VALUE_TYPE lh_ub = op1.upper_bound (); + lh_lb = real_value_negate (&lh_lb); + lh_ub = real_value_negate (&lh_ub); + r.set (type, lh_ub, lh_lb); + if (op1.maybe_isnan ()) + { + bool sign; + if (op1.nan_signbit_p (sign)) + r.update_nan (!sign); + else + r.update_nan (); + } + else + r.clear_nan (); + return true; + } + bool op1_range (frange &r, tree type, + const frange &lhs, const frange &op2, + relation_kind rel = VREL_VARYING) const final override + { + return fold_range (r, type, lhs, op2, rel); + } +} fop_negate; + class foperator_abs : public range_operator_float { using range_operator_float::fold_range; @@ -1593,6 +1639,7 @@ floating_op_table::floating_op_table () set (UNORDERED_EXPR, fop_unordered); set (ABS_EXPR, fop_abs); + set (NEGATE_EXPR, fop_negate); } // Return a pointer to the range_operator_float instance, if there is @@ -1633,6 +1680,21 @@ frange_float (const char *lb, const char *ub, tree type = float_type_node) void range_op_float_tests () { + frange r, r0, r1; + frange trange (float_type_node); + + // negate([-5, +10]) => [-10, 5] + r0 = frange_float ("-5", "10"); + fop_negate.fold_range (r, float_type_node, r0, trange); + ASSERT_EQ (r, frange_float ("-10", "5")); + + // negate([0, 1] -NAN) => [-1, -0] +NAN + r0 = frange_float ("0", "1"); + r0.update_nan (true); + fop_negate.fold_range (r, float_type_node, r0, trange); + r1 = frange_float ("-1", "-0"); + r1.update_nan (false); + ASSERT_EQ (r, r1); } } // namespace selftest -- 2.37.3