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: 58838 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 750903860753 for ; Fri, 14 Oct 2022 15:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 750903860753 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665760169; 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=taSQI7fbCLr3iqFz8AMkJwTIiYk0MK6DW8+Oyg7XdvW/diUjj7kEEZSDvwGft+won ZvWrmB4RXCRTo97z/q69yPT3mNywYdZCtE8vhibNu5wincnbKjjJ43c1+NJp6wqhIX tPV6h2dCEGLiRz5JaX4a7UY1HX2pRndw9hXeQvQc= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" [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.