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 2CE25385B1B3 for ; Mon, 5 Dec 2022 23:49:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CE25385B1B3 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=1670284149; h=from:from: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=Rq0iINyBxjt0YOsifts7KKUeu+2lQbPKfvIcCdfr3Dw=; b=WED7tE6ri5H26OGDcJYoCZOIVglpppPj9IJCEqfavnN1gY1tlM74jnH5qM7ChaBIFtSsHb 45Is2NZXfoFhPvPE44uDkIA7KPXeAn+4w5EymTsNypRCSTpLR8bPRG3eN9hYtkYilrNFzK bjraQxZNNdQUWbb3o3idw397YG39q9o= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-145-sHGGpojMP5m2SixUWtGl2A-1; Mon, 05 Dec 2022 18:49:08 -0500 X-MC-Unique: sHGGpojMP5m2SixUWtGl2A-1 Received: by mail-io1-f72.google.com with SMTP id b9-20020a056602218900b006dfecfefcfbso7297042iob.13 for ; Mon, 05 Dec 2022 15:49:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Rq0iINyBxjt0YOsifts7KKUeu+2lQbPKfvIcCdfr3Dw=; b=OEz2xd7B6dAlQihbO3UEhgFTt82xwK6nuzCvmpcTuqsHY9CPnKkP/Dt6TnvHLTzJzC GDriWaVzjuMMS+zubcOqez5KuBnPoElixHmzlHQbCq66uLUI8m0UU25n6pmUeJL/fXsl vzHJCR3XN/M33Yciq40nM0eNspXhG59hjik45OQV2PqWOXDW7DmM/eB9wN5Pqdxb4wYk ukoSpo1Jbz0J/k5orYpZ6is+DZ2Ma6kN5Uxaffu4WZhixzylA4jmCi63AcPW+MZevd92 zr7oqFAyHvTgFltI5UQLoAb3ha92P+6HsvDwbsy6NiucXF+fjuh6EqfG4hJingMPI6ej FFcA== X-Gm-Message-State: ANoB5plpel6+HiZy8yHagUDtBRe8pauQGrlawXVljcfgG28OVlakVx9t N0o8Ys7iYCmgQ8m91eCylltloV+TMW/fY73I1Y6Ng0pF90qsx9lAqJxDSR9B4udTeOqbuGYTvvN fO/S/cvisOMRROImctg== X-Received: by 2002:a92:cc43:0:b0:303:21bc:ffae with SMTP id t3-20020a92cc43000000b0030321bcffaemr13818873ilq.321.1670284147731; Mon, 05 Dec 2022 15:49:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4N4xlu7dygV/jkyEPdJ/Nn9YEoO7KKFlx3bR9lDmbPrwBRHnFN6tKMjFofU/DWkFv65xrs4g== X-Received: by 2002:a92:cc43:0:b0:303:21bc:ffae with SMTP id t3-20020a92cc43000000b0030321bcffaemr13818868ilq.321.1670284147385; Mon, 05 Dec 2022 15:49:07 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::6c01? ([2607:fea8:a263:f600::6c01]) by smtp.gmail.com with ESMTPSA id i44-20020a023b6c000000b00389e1142967sm6147750jaf.57.2022.12.05.15.49.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Dec 2022 15:49:06 -0800 (PST) Message-ID: <37201511-c11d-7750-cdc9-af33e5118c10@redhat.com> Date: Mon, 5 Dec 2022 18:49:05 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] range-op-float: Improve binary reverse operations To: Jakub Jelinek , Aldy Hernandez , gcc-patches@gcc.gnu.org References: <1f2b50a8-8f3c-690a-182b-c636fc2f86ed@redhat.com> <32b96813-616d-ba73-811f-8a36e70f9ecd@redhat.com> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 12/5/22 17:38, Jakub Jelinek wrote: > 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... Yeah thats also fine. Andrew > 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 >