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: 29659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2203892wrr; Mon, 5 Dec 2022 04:00:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MP+v5Y9waa+OQ70yRbeEPhIsn6YFITSRnYpLWNwpbFzar9vlpF35d80k7KEBOc7Da3gOe X-Received: by 2002:a17:906:844:b0:78c:2c03:804c with SMTP id f4-20020a170906084400b0078c2c03804cmr57069348ejd.107.1670241626323; Mon, 05 Dec 2022 04:00:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670241626; cv=none; d=google.com; s=arc-20160816; b=eG1ZIs58aM8Tl2uiP4SRutdmdmWrMb+DUaAXikTxxBxOY9jJQ6jzsgj9Q/zZwUm0NA aWsieVKqVPkwtslXSMViYn/9FQJIZStVLEy0bzpJXWbMq8ZEAGkY2fTQdJ37lM+Vn1t0 pQuLNi50VkHYT54KUmfD/87ZQFX+yVWlVzHdhrQjJjWRIj3jbUF8MjyBKg760AJ+w8Yk AfN7IrAxViEOJ+aH7ykOCrznnL4lcv5Z+yvEJGw1k4UcyCS9n7Y8nXWU2nB47r3aiX1V XSGm9S8hj3RnEDs71z0ahXjS1cIk2oaZx9cl0hbfOEsVTbiPOavJQMvtpIP4EfyIgh6w 7KAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=MEp7AdZLoB2jai7GmaCNJbIElZypoLA4TXVamrusW1o=; b=XtVlaqdlphhvVHHeTY1NRQqQJ2pykNKqEEn89egrek/lvF6N60tQBFLAoVpV9n6QsO lmMu1CpysEhcw5KpmZFNq756dzoevvrv9vL4wDVRhAlzFgwpJobdQeji1EAY9RNRcAUJ mp1NzdI7UoNofhAAOSJYUhdEDvOr1srvIkgLzf9ZLf6Bat6LvNT+Y/NX8G21XyQXhbxI 6L++r46tMK8+K22CRgCX1sEc24yRJqVVpxcdWmhihP96N/yy5lZEyXjs3Ksykg4xFpwT qy9mkac8b4W4lpyMkkDwpMuyobMzLaphrrhwszJAWfXRBQeyqiuchf91f8GkSG9NUt5E erDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ICHALaR3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b18-20020a0564021f1200b0046c8d52c8c7si3448635edb.177.2022.12.05.04.00.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 04:00:26 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ICHALaR3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 494EF3817765 for ; Mon, 5 Dec 2022 12:00:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 494EF3817765 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670241613; 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=ICHALaR3RgDi0uke6uaC3Iuiy5invTkK1hdNxPPpqy47YjyLY53L5mZn3gdxh4z10 IqBR2TmtjDHrDR5seC0b1NJRrf4WtNtFITKlTeO5iq6SJCwPmYCqLSqfp3wsrmOrrS Y6iC3YpEs0xsWDNmckC9/2UZuh8n/HoROaLc/gTA= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751375283388600967?= X-GMAIL-MSGID: =?utf-8?q?1751375283388600967?= 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,