From patchwork Mon Sep 11 17:42:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 75673 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 95C02385828D for ; Mon, 11 Sep 2023 17:42:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95C02385828D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694454166; bh=wrUks3bkzdGKGqqBBLh3PvSPugu9o41OJMVJdrGtSuc=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xruueRfgzdVAWlw8HU/DqTLQzu0ZKrPndkg192i3XFUgcnQBmZ7szpIb3ppn3+Iyv 4P4Z2R0qnEMgc/5IiS4XQnWd+WyKT2G3IN4BFQCeiFk30NrntBO/udjGx56hUONxjE zbCtvEhZX0aIGfIHOFAw0XVIz5SRrEebIhujwYl8= 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 C6C0F3858D38 for ; Mon, 11 Sep 2023 17:42:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6C0F3858D38 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-634-t2Ba9QZuNMeIKqZrTfxC0Q-1; Mon, 11 Sep 2023 13:42:17 -0400 X-MC-Unique: t2Ba9QZuNMeIKqZrTfxC0Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F6AE8D1D98; Mon, 11 Sep 2023 17:42:05 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.225.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9FFE407D47E; Mon, 11 Sep 2023 17:42:04 +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 38BHg2u33694282 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 11 Sep 2023 19:42:02 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38BHg2hh3694281; Mon, 11 Sep 2023 19:42:02 +0200 Date: Mon, 11 Sep 2023 19:42:02 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] small _BitInt tweaks Message-ID: 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 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_H3, 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" Hi! When discussing PR111369 with Andrew Pinski, I've realized that I haven't added BITINT_TYPE handling to range_check_type. Right now (unsigned) max + 1 == (unsigned) min for signed _BitInt,l so I think we don't need to do the extra hops for BITINT_TYPE (though possibly we don't need them for INTEGER_TYPE either in the two's complement word and we don't support anything else, though I really don't know if Ada or some other FEs don't create weird INTEGER_TYPEs). And, also I think it is undesirable when being asked for signed_type_for of unsigned _BitInt(1) (which is valid) to get signed _BitInt(1) (which is invalid, the standard only allows signed _BitInt(2) and larger), so the patch returns 1-bit signed INTEGER_TYPE for those cases. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-09-11 Jakub Jelinek gcc/ * tree.cc (signed_or_unsigned_type_for): Return INTEGER_TYPE for signed variant of unsigned _BitInt(1). * fold-const.cc (range_check_type): Handle BITINT_TYPE like OFFSET_TYPE. gcc/c-family/ * c-common.cc (c_common_signed_or_unsigned_type): Return INTEGER_TYPE for signed variant of unsigned _BitInt(1). Jakub --- gcc/tree.cc.jj 2023-09-06 17:50:30.707589026 +0200 +++ gcc/tree.cc 2023-09-11 16:24:58.749625569 +0200 @@ -11096,7 +11096,7 @@ signed_or_unsigned_type_for (int unsigne else return NULL_TREE; - if (TREE_CODE (type) == BITINT_TYPE) + if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1)) return build_bitint_type (bits, unsignedp); return build_nonstandard_integer_type (bits, unsignedp); } --- gcc/c-family/c-common.cc.jj 2023-09-06 17:34:24.467254960 +0200 +++ gcc/c-family/c-common.cc 2023-09-11 16:24:07.873300311 +0200 @@ -2739,7 +2739,9 @@ c_common_signed_or_unsigned_type (int un || TYPE_UNSIGNED (type) == unsignedp) return type; - if (TREE_CODE (type) == BITINT_TYPE) + if (TREE_CODE (type) == BITINT_TYPE + /* signed _BitInt(1) is invalid, avoid creating that. */ + && (unsignedp || TYPE_PRECISION (type) > 1)) return build_bitint_type (TYPE_PRECISION (type), unsignedp); #define TYPE_OK(node) \ --- gcc/fold-const.cc.jj 2023-09-11 11:05:47.473728473 +0200 +++ gcc/fold-const.cc 2023-09-11 16:28:06.052141516 +0200 @@ -5565,7 +5565,12 @@ range_check_type (tree etype) else return NULL_TREE; } - else if (POINTER_TYPE_P (etype) || TREE_CODE (etype) == OFFSET_TYPE) + else if (POINTER_TYPE_P (etype) + || TREE_CODE (etype) == OFFSET_TYPE + /* Right now all BITINT_TYPEs satisfy + (unsigned) max + 1 == (unsigned) min, so no need to verify + that like for INTEGER_TYPEs. */ + || TREE_CODE (etype) == BITINT_TYPE) etype = unsigned_type_for (etype); return etype; }