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 5ADAA385B1A7 for ; Mon, 5 Dec 2022 11:59:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5ADAA385B1A7 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=1670241569; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=MEp7AdZLoB2jai7GmaCNJbIElZypoLA4TXVamrusW1o=; b=H+3jzu8sP+E4LYLtMKUEG4UUeY55G7v3bzE4ULIgfpaJfETlQ9G1fXZVHld28SN+nz64bd 7eO/o6NvHCh8ggHXPiPJfMH6tK7/JSn5EaD13ThfDDvxZMw69r2LNhd/OvWdvoF9NMftpP AlyHhPgSdIO5hyKQu4TMfWuKAFUQ184= 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-387-j64eGI6lNUSKhBw6Ac_TZw-1; Mon, 05 Dec 2022 06:59:28 -0500 X-MC-Unique: j64eGI6lNUSKhBw6Ac_TZw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 755073813F20 for ; Mon, 5 Dec 2022 11:59:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12BE440C6EC3; Mon, 5 Dec 2022 11:59:27 +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 2B5BxCbK3416473 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 5 Dec 2022 12:59:18 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B5BxCYq3416472; Mon, 5 Dec 2022 12:59:12 +0100 Date: Mon, 5 Dec 2022 12:59:11 +0100 From: Jakub Jelinek To: Aldy Hernandez Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op-float: Improve multiplication reverse operation Message-ID: Reply-To: Jakub Jelinek References: <1f2b50a8-8f3c-690a-182b-c636fc2f86ed@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.9 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 10:54:41AM +0100, Aldy Hernandez wrote: > > Do you mind if I try that incrementally and only if it doesn't make the > > code too large/too unreadable? > > Sure. And don't feel obligated to implement it either. range-ops is a > never ending pit of possible optimizations. We found that out quite early > in the design. > > If you don't get to it, could you at least add a comment? So like this for multiplication op1/2_range if it passes bootstrap/regtest? For division I'll need to go to a drawing board... 2022-12-05 Jakub Jelinek * range-op-float.cc (zero_to_max_range): New function. (foperator_plus::op1_range): If lhs can't be INF nor NAN, op1 can't be INF. --- gcc/range-op-float.cc.jj 2022-12-05 11:17:34.900573272 +0100 +++ gcc/range-op-float.cc 2022-12-05 12:32:30.286753929 +0100 @@ -2004,6 +2004,29 @@ zero_to_inf_range (REAL_VALUE_TYPE &lb, } } +// Set [lb, ub] to [-MAX, -0], [-MAX, +MAX] or [+0, +MAX] depending on +// signbit_known. +static void +zero_to_max_range (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, tree type, + int signbit_known) +{ + if (signbit_known > 0) + { + lb = dconst0; + ub = real_max_representable (type); + } + else if (signbit_known < 0) + { + lb = real_min_representable (type); + ub = real_value_negate (&dconst0); + } + else + { + lb = real_min_representable (type); + ub = real_max_representable (type); + } +} + class foperator_plus : public range_operator_float { using range_operator_float::op1_range; @@ -2159,7 +2182,14 @@ public: // and perhaps if it can be NAN or not. REAL_VALUE_TYPE lb, ub; int signbit_known = signbit_known_p (lhs_lb, lhs_ub, op2_lb, op2_ub); - zero_to_inf_range (lb, ub, signbit_known); + // If lhs can't be +-INF nor NAN, then op1 can't be +-INF - + // +-INF * anything is either +-INF or NAN (if op2 is +-0 or NAN). + if (!real_isinf (&lhs_lb) + && !real_isinf (&lhs_ub) + && !lhs.maybe_isnan ()) + zero_to_max_range (lb, ub, type, signbit_known); + else + zero_to_inf_range (lb, ub, signbit_known); r.set (type, lb, ub); } // Otherwise, if op2 is a singleton INF and lhs doesn't include INF, Jakub