From patchwork Tue Sep 5 07:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 75253 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 5B5713857C43 for ; Tue, 5 Sep 2023 07:28:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B5713857C43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693898915; bh=CWVuM+PF+VeXBqYuK7AXEJ0qx5/1/7papUx6+jLcucc=; 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=luaKRzBWyu9WB0w3t2DZwr1ERYVUn0w0fSLv6plJKCCbdyskAlvPDjTM24j4jtWIF +s8n6ilRIWSMlq8rai0SSpz/qP7DjRZLKO3JaNNZdeOiDgmp273DT7T22YDRG8w3qo xolfGgCOg7fmgBvrpjV4JFROfDa4H7iVioczndSw= 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 3E8043858D32 for ; Tue, 5 Sep 2023 07:28:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E8043858D32 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-446-fi2ck-ozMhGFAtjIYIR8MQ-1; Tue, 05 Sep 2023 03:28:04 -0400 X-MC-Unique: fi2ck-ozMhGFAtjIYIR8MQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F3CC937705; Tue, 5 Sep 2023 07:28:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7D421182E9; Tue, 5 Sep 2023 07:28:03 +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 3857S1Re2876992 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Sep 2023 09:28:02 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3857S1xx2876991; Tue, 5 Sep 2023 09:28:01 +0200 Date: Tue, 5 Sep 2023 09:28:01 +0200 To: Andrew Pinski , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH 17/12] _BitInt a ? ~b : b match.pd fix [PR102989] Message-ID: References: <20230809191954.2668047-1-apinski@marvell.com> MIME-Version: 1.0 In-Reply-To: <20230809191954.2668047-1-apinski@marvell.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H4, RCVD_IN_MSPIKE_WL, 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.30 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Wed, Aug 09, 2023 at 12:19:54PM -0700, Andrew Pinski via Gcc-patches wrote: > PR tree-optimization/110937 > PR tree-optimization/100798 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -6460,6 +6460,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (if (cmp == NE_EXPR) > { constant_boolean_node (true, type); }))))))) > > +#if GIMPLE > +/* a?~t:t -> (-(a))^t */ > +(simplify > + (cond @0 @1 @2) > + (if (INTEGRAL_TYPE_P (type) > + && bitwise_inverted_equal_p (@1, @2)) > + (with { > + auto prec = TYPE_PRECISION (type); > + auto unsign = TYPE_UNSIGNED (type); > + tree inttype = build_nonstandard_integer_type (prec, unsign); > + } > + (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2)))))) > +#endif This broke one bitint test - bitint-42.c for -O1 and -Os (in admittedly not yet committed series). Using build_nonstandard_integer_type this way doesn't work well for larger precision BITINT_TYPEs, because it always creates an INTEGER_TYPE and say 467-bit INTEGER_TYPE doesn't work very well. To get a BITINT_TYPE, one needs to use build_bitint_type instead (but similarly to build_nonstandard_integer_type one should first make sure such a type actually can be created). I admit it isn't really clear to me what do you want to achieve by the above build_nonstandard_integer_type. Is it because of BOOLEAN_TYPE or perhaps ENUMERAL_TYPE as well? If type is INTEGER_TYPE or BITINT_TYPE, one doesn't really need to create a new type, type already is an integral type with that precision and signedness. In other places using unsigned_type_for or signed_type_for might be better than using build_nonstandard_integer_type if that is what one wants to achieve, those functions handle BITINT_TYPE. Or shall we instead test for == BOOLEAN_TYPE (or if ENUMERAL_TYPE for some reason needs the same treatment also || == ENUMERAL_TYPE)? 2023-09-05 Jakub Jelinek PR c/102989 * match.pd (a ? ~b : b): Don't use build_nonstandard_integer_type for INTEGER_TYPE or BITINT_TYPE. Jakub --- gcc/match.pd.jj 2023-09-04 09:45:33.553058301 +0200 +++ gcc/match.pd 2023-09-05 08:45:53.258078971 +0200 @@ -6631,7 +6631,9 @@ (define_operator_list SYNC_FETCH_AND_AND (with { auto prec = TYPE_PRECISION (type); auto unsign = TYPE_UNSIGNED (type); - tree inttype = build_nonstandard_integer_type (prec, unsign); + tree inttype = type; + if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != BITINT_TYPE) + inttype = build_nonstandard_integer_type (prec, unsign); } (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2))))))) #endif