From patchwork Mon Dec 5 11:59:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61472 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D0683898C6C for ; Mon, 5 Dec 2022 11:59:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D0683898C6C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670241598; bh=MEp7AdZLoB2jai7GmaCNJbIElZypoLA4TXVamrusW1o=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vIhhIMmA3AxTKXqJ/GsTwWrYn49f8A8BJsfzIUdueWmPRk5XRx4j4sWKQpMLnEVZS d2wNL1rolpF+/fKJDZ+dPzs2DQcGkFqZJddp1GSxG45c2VoLxMvQpmcREVukH9rgRQ TcxB7ETKwOR63hNnHLyIkhGs1LL/AGAgt0OJqiBM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 To: Aldy Hernandez Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op-float: Improve multiplication reverse operation Message-ID: 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-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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Jakub --- 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,