From patchwork Sun Nov 13 20:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 19432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1815840wru; Sun, 13 Nov 2022 12:06:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wQ1HoPmMHE8yD0ZRDBBbAqcpDvEyOYXfge66DgnRUfClfaKQFuXdgzGzUoK6f37s3Ijbi X-Received: by 2002:a05:6402:5488:b0:462:317a:e02f with SMTP id fg8-20020a056402548800b00462317ae02fmr9011168edb.125.1668370015602; Sun, 13 Nov 2022 12:06:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668370015; cv=none; d=google.com; s=arc-20160816; b=sCtbw67ia9LwXpdZJIW9IHsnpDqGZcmpBct2TT1yzJToqrvJ+dlOjwpUJV2RIJ9Xn2 7uaHj/gOEpnTUv41wl2hq5ZTUEnFkJtAlaB0uRak0ABfZ9P08OiAulkvcc/GZisyNZ3t sTCOdxzoUxWfmoTpBzyJE5O5/XZMR/H12yeSoWP3u38qagmH/FhqE3LGk/x2KZK2LJt0 BhnuAk1o2BZCJKYPcerJz8I3qXkP3VVbWUH5oDRy1e+YHF24piWlPu7Lg3cuNkdIjug2 R25m9oF6Ab5d8qo97mJwrDEUYQ1cqrbf4WwWOfI3amZBGhya88FAa8+tDDLDI+me9Eac WIMQ== 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-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bYVE4JckG+vPhRnIfQUZGevxKO7X1+zfsyX0zfTl2xk=; b=uGcfEd/WTLqfw+AOKZ7DAuGHYETB7LhdWCB7i80TWTjFPTFMj+PAq2NwlY1hTSrns9 ATrmg2wueG6B0nXGT+mAlT+ZcCqqd+J8VRjclHaVB37CycJ64oZp33SmDULSELm12BWP ZoMzTdZFfmuoVg/BxR/vhUWxtLzLrGYthuMGKu/FI0TJK9QCDUJ5YlYFbmSSRVyk57At n31lp7BW3WcB8dTxvJ35IwvpO6EOX/RE771cjtlBPsElcXgengq/eBCZMtmgEow0mpUV 5w1XX11lL3CUTNyUJLa7+gXFO0Pr6xKj4xU+IHaK0UGYR5aFlS/z6PCDvHvNIaD5DRBi HcIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hVVAm1V+; 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 va29-20020a17090711dd00b007adca6532e3si5923956ejb.229.2022.11.13.12.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Nov 2022 12:06:55 -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=hVVAm1V+; 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 60B5C3857B98 for ; Sun, 13 Nov 2022 20:06:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60B5C3857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668370014; bh=bYVE4JckG+vPhRnIfQUZGevxKO7X1+zfsyX0zfTl2xk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hVVAm1V+s5Y0fL6vv2KggK2fuXGNQf/2exhxIaWbqK8DKCBBte0XCPTBQmRvFHxBJ w8Gh4MGM27k+esOszvk76MXCfKI10SOCmrrI4SdQPgAsIcnMNevC25AO1bJTELN5jg eK6JeWCcQsG+3FdQoyGlJLBR7zSwiDuMCzzCEVME= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 92C6D3857BB3 for ; Sun, 13 Nov 2022 20:06:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92C6D3857BB3 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-34-Y36HQ7YIM6WlTEV2xA-Tkw-1; Sun, 13 Nov 2022 15:06:03 -0500 X-MC-Unique: Y36HQ7YIM6WlTEV2xA-Tkw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 920958001B8 for ; Sun, 13 Nov 2022 20:06:03 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B6C8111E3E4; Sun, 13 Nov 2022 20:06:03 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 2ADK5wHi440753 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 13 Nov 2022 21:05:58 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2ADK5wAN440752; Sun, 13 Nov 2022 21:05:58 +0100 To: Jakub Jelinek Cc: GCC patches , Andrew MacLeod , Aldy Hernandez Subject: [PATCH] [range-ops] Implement sqrt. Date: Sun, 13 Nov 2022 21:05:53 +0100 Message-Id: <20221113200553.440728-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez 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?1749412757236254077?= X-GMAIL-MSGID: =?utf-8?q?1749412757236254077?= It seems SQRT is relatively straightforward, and it's something Jakub wanted for this release. Jakub, what do you think? p.s. Too tired to think about op1_range. gcc/ChangeLog: * gimple-range-op.cc (class cfn_sqrt): New. (gimple_range_op_handler::maybe_builtin_call): Add cases for sqrt. --- gcc/gimple-range-op.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 7764166d5fb..240cd8b6a11 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "range.h" #include "value-query.h" #include "gimple-range.h" +#include "fold-const-call.h" // Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names // on the statement. For efficiency, it is an error to not pass in enough @@ -301,6 +302,41 @@ public: } } op_cfn_constant_p; +// Implement range operator for SQRT. +class cfn_sqrt : public range_operator_float +{ + using range_operator_float::fold_range; +private: + REAL_VALUE_TYPE real_sqrt (const REAL_VALUE_TYPE &arg, tree type) const + { + tree targ = build_real (type, arg); + tree res = fold_const_call (as_combined_fn (BUILT_IN_SQRT), type, targ); + return *TREE_REAL_CST_PTR (res); + } + void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan, + tree type, + const REAL_VALUE_TYPE &lh_lb, + const REAL_VALUE_TYPE &lh_ub, + const REAL_VALUE_TYPE &, + const REAL_VALUE_TYPE &, + relation_kind) const final override + { + if (real_compare (LT_EXPR, &lh_ub, &dconst0)) + { + real_nan (&lb, "", 0, TYPE_MODE (type)); + ub = lb; + maybe_nan = true; + return; + } + lb = real_sqrt (lh_lb, type); + ub = real_sqrt (lh_ub, type); + if (real_compare (GE_EXPR, &lh_lb, &dconst0)) + maybe_nan = false; + else + maybe_nan = true; + } +} fop_cfn_sqrt; + // Implement range operator for CFN_BUILT_IN_SIGNBIT. class cfn_signbit : public range_operator_float { @@ -907,6 +943,12 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_parity; break; + CASE_CFN_SQRT: + CASE_CFN_SQRT_FN: + m_valid = true; + m_float = &fop_cfn_sqrt; + break; + default: break; }