From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E1BE53858C83 for ; Fri, 14 Oct 2022 16:06:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1BE53858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665763568; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=uwzXSJR92JsRrpGvK3KTrQwYwGqAIa5w+ygmey5tUC8=; b=EoM1UxfacolNOxPwj5g2qTHB6if7Bf68yEeBq5SfXtm95GNvwiWz4hB5QKmhBnDqi7qajK f2li+nRAfPq8E3r/Gl4bHqlmhRviGjP/o1J5W271UNnrTZeMxqDYImA1OWPrCQGOo6u/Iy RRbedvkZHywor+FpdRi71eV8OjpZz4I= 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-584-f63KLwC2M0GqYwRc-VbIYw-1; Fri, 14 Oct 2022 12:06:07 -0400 X-MC-Unique: f63KLwC2M0GqYwRc-VbIYw-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 3EE51185A792 for ; Fri, 14 Oct 2022 16:06:07 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7F4D40398B1; Fri, 14 Oct 2022 16:06:05 +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 29EG63rV2566634 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 14 Oct 2022 18:06:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29EG62mI2566633; Fri, 14 Oct 2022 18:06:02 +0200 Date: Fri, 14 Oct 2022 18:06:02 +0200 From: Jakub Jelinek To: Aldy Hernandez Cc: GCC patches , Andrew MacLeod Subject: Re: [PATCH] Implement range-op entry for __builtin_copysign. Message-ID: Reply-To: Jakub Jelinek References: <20221014150851.677560-1-aldyh@redhat.com> MIME-Version: 1.0 In-Reply-To: <20221014150851.677560-1-aldyh@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-9.6 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 List-Id: On Fri, Oct 14, 2022 at 05:08:51PM +0200, Aldy Hernandez wrote: > [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): CASE_CFN_COPYSIGN_ALL: instead. Otherwise LGTM. > + 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. > -- > 2.37.3 Jakub