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.133.124]) by sourceware.org (Postfix) with ESMTPS id CB9473855156 for ; Mon, 5 Dec 2022 22:39:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB9473855156 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=1670279942; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=siupTqlyrOx6eDe5BjUL2EQK9mZhPoqnzpRbgOOR9gE=; b=FZGcyMyN1G4NQU9lKih9hH6XS+cZPBE2ioZRACLptuEFCRJweuLf4+p/GUijJW6665lKj4 lBsUWf1ry0mRT7LHXLhTNNqzSqEyrllNiwbt0KzKQvmdMK/MsuK5qO6LfGvO90NhM6DY0r S8/V+HJS9fQw7ys+EI+h+kp6q4ywYBU= 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-304-vGo3dFinN2yKwi-bo3zlJw-1; Mon, 05 Dec 2022 17:39:01 -0500 X-MC-Unique: vGo3dFinN2yKwi-bo3zlJw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 403ED811E67 for ; Mon, 5 Dec 2022 22:39:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 012AA4EA61; Mon, 5 Dec 2022 22:39:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2B5Mcuve3424810 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 5 Dec 2022 23:38:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B5McuOd3424809; Mon, 5 Dec 2022 23:38:56 +0100 Date: Mon, 5 Dec 2022 23:38:56 +0100 From: Jakub Jelinek To: Andrew MacLeod , Aldy Hernandez , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] range-op-float: Improve binary reverse operations Message-ID: Reply-To: Jakub Jelinek References: <1f2b50a8-8f3c-690a-182b-c636fc2f86ed@redhat.com> <32b96813-616d-ba73-811f-8a36e70f9ecd@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 List-Id: On Mon, Dec 05, 2022 at 09:54:09PM +0100, Jakub Jelinek via Gcc-patches wrote: > On Mon, Dec 05, 2022 at 03:43:16PM -0500, Andrew MacLeod wrote: > > Id actually prefer to avoid passing the tree code around... we're trying to > > avoid that sort of thing even though Aldy temporarily introduced them to > > range-ops. Hes suppose to remove that next stage 1 :-P   Ideally anything > > "special" is locally contained to the specific routine. > > Would a bool divide_op2 argument be better (perhaps defaulted to false)? > Inlining float_binary_op_range_finish by hand doesn't seem to be a good > idea, if it needs to be changed, it would need to be changed in multiple > places... In patch form on top of PR107975 patch. 2022-12-05 Jakub Jelinek PR tree-optimization/107972 * range-op-float.cc (frange_drop_infs): New function. (float_binary_op_range_finish): Add DIV_OP2 argument. If DIV_OP2 is false and lhs is finite or if DIV_OP2 is true and lhs is non-zero and not NAN, r must be finite too. (foperator_div::op2_range): Pass true to DIV_OP2 of float_binary_op_range_finish. --- gcc/range-op-float.cc.jj 2022-12-05 11:17:34.900573272 +0100 +++ gcc/range-op-float.cc 2022-12-05 16:13:54.414845672 +0100 @@ -330,6 +330,18 @@ frange_drop_ninf (frange &r, tree type) r.intersect (tmp); } +// Crop R to [MIN, MAX] where MAX is the maximum representable number +// for TYPE and MIN the minimum representable number for TYPE. + +static inline void +frange_drop_infs (frange &r, tree type) +{ + REAL_VALUE_TYPE max = real_max_representable (type); + REAL_VALUE_TYPE min = real_min_representable (type); + frange tmp (type, min, max); + r.intersect (tmp); +} + // If zero is in R, make sure both -0.0 and +0.0 are in the range. static inline void @@ -1883,7 +1895,7 @@ foperator_unordered_equal::op1_range (fr static bool float_binary_op_range_finish (bool ret, frange &r, tree type, - const frange &lhs) + const frange &lhs, bool div_op2 = false) { if (!ret) return false; @@ -1904,7 +1916,20 @@ float_binary_op_range_finish (bool ret, // If lhs isn't NAN, then neither operand could be NAN, // even if the reverse operation does introduce a maybe_nan. if (!lhs.maybe_isnan ()) - r.clear_nan (); + { + r.clear_nan (); + if (div_op2 + ? !(real_compare (LE_EXPR, &lhs.lower_bound (), &dconst0) + && real_compare (GE_EXPR, &lhs.upper_bound (), &dconst0)) + : !(real_isinf (&lhs.lower_bound ()) + || real_isinf (&lhs.upper_bound ()))) + // For reverse + or - or * or op1 of /, if result is finite, then + // r must be finite too, as X + INF or X - INF or X * INF or + // INF / X is always +-INF or NAN. For op2 of /, if result is + // non-zero and not NAN, r must be finite, as X / INF is always + // 0 or NAN. + frange_drop_infs (r, type); + } // If lhs is a maybe or known NAN, the operand could be // NAN. else @@ -2330,7 +2355,7 @@ public: if (!ret) return ret; if (lhs.known_isnan () || op1.known_isnan () || op1.undefined_p ()) - return float_binary_op_range_finish (ret, r, type, lhs); + return float_binary_op_range_finish (ret, r, type, lhs, true); const REAL_VALUE_TYPE &lhs_lb = lhs.lower_bound (); const REAL_VALUE_TYPE &lhs_ub = lhs.upper_bound (); const REAL_VALUE_TYPE &op1_lb = op1.lower_bound (); @@ -2347,7 +2372,7 @@ public: zero_to_inf_range (lb, ub, signbit_known); r.set (type, lb, ub); } - return float_binary_op_range_finish (ret, r, type, lhs); + return float_binary_op_range_finish (ret, r, type, lhs, true); } private: void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan, Jakub