From patchwork Fri Oct 14 15:08:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 2724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp232034wrs; Fri, 14 Oct 2022 08:09:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EDFvoc7ONRGEILJBca6NbXem0bxAnnrCoQfGPJFBOSd22VSeYza66yZpZwy+tmyCQiRBE X-Received: by 2002:a17:906:dac9:b0:780:ab6f:591f with SMTP id xi9-20020a170906dac900b00780ab6f591fmr3875329ejb.77.1665760184371; Fri, 14 Oct 2022 08:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665760184; cv=none; d=google.com; s=arc-20160816; b=rOuFQSfvrEVHUCK+2ducXrxtw8WVU1Zy++9nA5yYznoY5o1tKWA5BlUBom3Z3HPA8b +ZGQ25iimFZrrVZsHauaw8whFKumiMlCbjotqhBnIBFmylRM28ae3cGgckvtBXMkEzD0 QXRMdQIKk5/jiMmvQTHpRPlJ9CeQVjThrSf6hMZ2/QrccZ/wq90rajd9rqDutzhpBv88 82pZodf4BQmDrsqWADrW6h6uzCw2oex6S5m0Dk8gpZ0NQI1zAGASTeoJHVaLveVME2PE jgvAlKKsZzAnWRLlgoGC6E3xbcDH/OyFCQ8uL2irkc0C7yeLfu5dpVMlF0zB/kU7eV1/ 7how== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=SM0PBSnR5pvfNowfXZoHkVISEdrPA+sr/xi9iiawogg=; b=Qseo++EAhBbCaLj+u14CEZi7b9bLvkD/O92/sjNGqxmNi3+mOjydu8Q6P6bEaD9yl+ FU/kc6j/V3gVEJ/zZILWkylWCtXXbzXrDfd/Rj04TuSv8w7n/YdLOpMPvIo8+plEsEQu DgFcI0G4n89DvPW0R7qjZfR6UxNVpocouN+VQKOXihh4TbhIeILZpBarHOdthSisaVEW 8GDBWIky3210UPO6/K0mcoZcj3/6WlKQbLdmNMTXdTctFtQy/YY6Nwyoe4W5G2gcp8As X3aGf6kO4YhEwaSrLliG/EIAmpXu7S5U9gc066bZVOHiTjf/QCaqfzt2uI3j20h6sdAs 7gCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pVaEuk6V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id i6-20020a170906114600b007824b741e7asi2307412eja.236.2022.10.14.08.09.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 08:09:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pVaEuk6V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 6EA44386076D for ; Fri, 14 Oct 2022 15:09:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6EA44386076D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665760183; bh=SM0PBSnR5pvfNowfXZoHkVISEdrPA+sr/xi9iiawogg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pVaEuk6V5c+M21orwQsTg1Pp+uA4z8xzSzyNR23HcR8HZW68Pq+Bpl1JPMiV+SMWe nYO0GSKtYb21no3d3jW6Nf6UWt9M9pMIpKQzbGNi+jOZXVzxk+qBBCQfkeLoQO1g1Y zXZ7TYWsybBNa8kbDVg5DdCOOuiBDT8NTFsoswXA= 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 020F438582B7 for ; Fri, 14 Oct 2022 15:08:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 020F438582B7 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-156-p1_jmPS7NmK-P_ZR2UHjrA-1; Fri, 14 Oct 2022 11:08:58 -0400 X-MC-Unique: p1_jmPS7NmK-P_ZR2UHjrA-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 30E748041B5 for ; Fri, 14 Oct 2022 15:08:58 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBBED40C958D; Fri, 14 Oct 2022 15:08:57 +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 29EF8tQn677580 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 14 Oct 2022 17:08:55 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29EF8tU3677579; Fri, 14 Oct 2022 17:08:55 +0200 To: Jakub Jelinek Subject: [PATCH] Implement range-op entry for __builtin_copysign. Date: Fri, 14 Oct 2022 17:08:51 +0200 Message-Id: <20221014150851.677560-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 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, 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 Cc: GCC patches 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?1746676151305066255?= X-GMAIL-MSGID: =?utf-8?q?1746676151305066255?= [Jakub, while we're on the subject of signed zeros and copysign, does this look OK to you?] copysign(MAGNITUDE, SIGN) is implemented as the absolute of MAGNITUDE, with SIGN applied. If the sign of "SIGN" cannot be determined, we return a range of [-MAGNITUDE, +MAGNITUDE]. gcc/ChangeLog: * gimple-range-op.cc (class cfn_copysign): New. (gimple_range_op_handler::maybe_builtin_call): Add CFN_BUILT_IN_COPYSIGN*. --- gcc/gimple-range-op.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 527893f66af..8137308f32e 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -342,6 +342,38 @@ public: } } op_cfn_signbit; +// Implement range operator for CFN_BUILT_IN_COPYSIGN +class cfn_copysign : public range_operator_float +{ +public: + using range_operator_float::fold_range; + virtual bool fold_range (frange &r, tree type, const frange &lh, + const frange &rh, relation_kind) const override + { + frange neg; + range_op_handler abs_op (ABS_EXPR, type); + range_op_handler neg_op (NEGATE_EXPR, type); + if (!abs_op || !abs_op.fold_range (r, type, lh, frange (type))) + return false; + if (!neg_op || !neg_op.fold_range (neg, type, r, frange (type))) + return false; + + bool signbit; + if (rh.signbit_p (signbit)) + { + // If the sign is negative, flip the result from ABS, + // otherwise leave things positive. + if (signbit) + r = neg; + } + else + // If the sign is unknown, keep the positive and negative + // alternatives. + r.union_ (neg); + return true; + } +} op_cfn_copysign; + // Implement range operator for CFN_BUILT_IN_TOUPPER and CFN_BUILT_IN_TOLOWER. class cfn_toupper_tolower : public range_operator { @@ -762,6 +794,13 @@ gimple_range_op_handler::maybe_builtin_call () m_valid = true; break; + CASE_FLT_FN (CFN_BUILT_IN_COPYSIGN): + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_float = &op_cfn_copysign; + m_valid = true; + break; + case CFN_BUILT_IN_TOUPPER: case CFN_BUILT_IN_TOLOWER: // Only proceed If the argument is compatible with the LHS.