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: 137913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2225433vqo; Mon, 11 Sep 2023 10:43:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgH+8rwZGT5bBqY610bwWVRNZSzqVRvP3sw//kLftjltv8/QXKo1HGAB9Gsr61qLCLbVOd X-Received: by 2002:a05:6512:2345:b0:502:c615:99a9 with SMTP id p5-20020a056512234500b00502c61599a9mr1979035lfu.30.1694454182062; Mon, 11 Sep 2023 10:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694454182; cv=none; d=google.com; s=arc-20160816; b=qaityGKirH1zNH4r9N8kZCoqzswUGR3FNyAfreT5KhvhNLWyVNSc5i1+BEAJxCReE9 /ePoM/02bUiuNOTstyA3MsyRehwgvXhCTpBFNT/xKd6Udtn1dHYnnaTGYPwGIFY3ECYc LXm0827mlNp5eqaze6WIu+FL3wwX4BTewCwt9y1RhSHGpqOQdaS/suYylASdMz9BP/Ce XZwC37l0qpbbRbmZ51wP0CCLGSSziAVmPMdVgKUTucdtCQLeA2GfZN1BgS6vO3BahDeX AVFMmdwBRNy6G2zyxIUQE9tNojUJ14fX2Fu3URWliIFk16dIkBCj++k79HhffSmMFxRm ipOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wrUks3bkzdGKGqqBBLh3PvSPugu9o41OJMVJdrGtSuc=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=k7YuDELVfPsKy91v+ng006S2WWLWXpW+VcsH2V8cIsiiwAcUvwBLVg2pEFSFY85jAL uuBAEbwRUXZkriuHLGYsyYbGigHiIjxycstcg8VL2UrsTzQrhi3aBghSV91S8bYKcaN5 jHFOx4rbF9dcgxWDjg7j2/s8LxlwoBO5U5LXPVk/p+HKm3igHtkcNYZm++Nk2x+oNl8l 9BtzHOwbClz21EyekN1hlop/PGCukO0UeqRH9FubuHvyDdksO0qKO0oNJllvVMi82SR/ qny6+EriKWD9S3gULVPfnJeU9HGWUgfnzBb+JpCl5MGX4SlraG+dizJfamOg5RX9mpZq BzxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l0qw6zDD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a20-20020a170906685400b009935121ecd7si7834001ejs.639.2023.09.11.10.43.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 10:43:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l0qw6zDD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 AFD093858D38 for ; Mon, 11 Sep 2023 17:43:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFD093858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694454180; bh=wrUks3bkzdGKGqqBBLh3PvSPugu9o41OJMVJdrGtSuc=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=l0qw6zDD82lVY/EcMeowWMbM1GSl1hoBRTGvSfFDC6aIwtuVTnbnZ5Pkr4Rbmco3T /fgRtPGDeYD2ZDHGSMEVNvEHOdTOiCva2H52gi6tXNQ+lbRFxk0hy3BDY2pirsnwp0 E9bJAsUAkmBBb7XQWpfKRCS4hgUm8txkgBQdNqlE= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776763988241278494 X-GMAIL-MSGID: 1776763988241278494 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; }