From patchwork Fri Feb 2 09:52:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 195761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp317547dyc; Fri, 2 Feb 2024 01:53:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnVRAMG2H32UGSN3v0MACFC/y7nOJtfZKS0HaqK3jVRMVp4/Y4+TQSfvIWyo0tp10VrIUG X-Received: by 2002:a05:622a:64d:b0:42b:e2fa:5b34 with SMTP id a13-20020a05622a064d00b0042be2fa5b34mr7670205qtb.57.1706867630046; Fri, 02 Feb 2024 01:53:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706867630; cv=pass; d=google.com; s=arc-20160816; b=E68Q/zXHfyLpBgiC1PE9OTTEIskUyS+MP2vtPn43yTXVzUeHxImSwX2Ne212O1XeJt T6/PeXk5LiXpxHsP872i8ClTiqhXLR+yg/rPe3n3W+KoQE3675ssDVXxySHBxVQe+jlH P1jS9gGajnOohd6jVJOiFC8pFAXBniBSb4xIRhuxFVKZLV/KH7RkTpeHRgu37zlpY9eX Y+4N1+zPZAB6WuKcoZ3nqRAks79aas98WT/uI7v5UhY7diydv6/s6Zf4JuvKBiEmFjBP eRUCaDB6eGiE42u7OOwfXGv3SeK2BK7NMEQqft2JdFy+G0mchfdMs7rCcs7X6JSbspIg vtKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=3B7M3mVezKJ2UNfWBOCBXvFBj7xJru96ORPLOjAVdmg=; fh=gzAIld1cIvv3m6+TzdZBnZcQ0bBSWZt4iATz9rWZ22c=; b=0oKs+BBfOcg6sSWWLYU4SgSazhQ3ca9Hkbu+yNTF+9NMGPpNJHHn2Grj3bzlpSF9Ru did3AmD6+fMXc4QS+S3qyakHC6mqinuMpBtdWyFDUZLUvOT/RZzQV/6fMiAeHwpuNddk xN+sb1f7Nl5uHrVNaKyaDefUGjSDEvfsud432i6GI6osPo54zX9kTi1DUH1jztaabBWi YC7c5LTm8TTdqM+gsY6iXZ4k58qjpPFedRR2amnSipESsnkshu21JgzJ7pSttoaDMaJj jpgv+LQMD0a7pGci9XSTHx8vlpD1kmgogLPa6Z/FhaiRNe50iISHCzM0ts9c9zwY+yJl tFLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KUUhzL33; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWm4dwHbd5+t1vEjm3R3UgufPBv9DJAYTryi04SHCNgCUdAbRVDxteiM2aR+R7Y0IQai5cz6iRCoUpZ2gDbvTZAJEKlMw== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t10-20020a05622a148a00b0042ab4a32c1dsi1552903qtx.385.2024.02.02.01.53.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:53:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KUUhzL33; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C7733857C65 for ; Fri, 2 Feb 2024 09:53:49 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0918A385801E for ; Fri, 2 Feb 2024 09:52:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0918A385801E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0918A385801E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706867579; cv=none; b=eeBgegnjtWLxI6TGMEGaZz45ggUzwlwgyn52P3fwaNsxm8rCqKFjH1Xemz/eqK2jDdkQ9xS43y6uyPk21+nciafe4Ljndk2Df6asMpPrZiDTyy8BFYzSKR887aWSPBbJR8Og69zPmlQCUbo5PH8UNmjqZk1NryLt1/p2hFP8abw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706867579; c=relaxed/simple; bh=fGyJW53WHvAn2sH49AGJEvrGku0x1AUnRd/rqFuKt+4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=DbZHYmTVuB/hBcHibmHiaYqb7+w7OUbH8YdeVniSrQMMNia3lxXvc8uVMuBx8BBW3MdqdmL7LyQLZp7kcxk/X4z+/D+u6LySzRxgjJHnN9A0CphIahXwPy/N0o1atDO48PMecNogreyKKCjCnmv10Fct9pEc773zTqefOKm3uzE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706867576; 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; bh=3B7M3mVezKJ2UNfWBOCBXvFBj7xJru96ORPLOjAVdmg=; b=KUUhzL33S3w6n9VUMcZb/eheINZiISR13cqGc4erHw5ED+A8j18d5HqmXrfK+r9FRGUNpS W2ciHBsKRuyVmW8MURUfMgyk2TYvbE/XdOyFr0UV/VFq5QTPEQZ/xufttHaOcwCDRj3nag PQZx/ayLzUsLQSwMFNnJJLsHaCDFBAs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-FcfonaJfPe6ois047kTxTA-1; Fri, 02 Feb 2024 04:52:55 -0500 X-MC-Unique: FcfonaJfPe6ois047kTxTA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D21F288B764; Fri, 2 Feb 2024 09:52:54 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95D65492BE2; Fri, 2 Feb 2024 09:52:54 +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 4129ql6j2705569 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 2 Feb 2024 10:52:48 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4129qlnt2705568; Fri, 2 Feb 2024 10:52:47 +0100 Date: Fri, 2 Feb 2024 10:52:46 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Handle casts from large/huge _BitInt to pointer/reference types [PR113692] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.5 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789780431984811176 X-GMAIL-MSGID: 1789780431984811176 Hi! I thought one needs to cast first to pointer-sized integer before casting to pointer, but apparently that is not the case. So the following patch arranges for the large/huge _BitInt to pointer/reference conversions to use the same code as for conversions of them to small integral types. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-02 Jakub Jelinek PR tree-optimization/113692 * gimple-lower-bitint.cc (bitint_large_huge::lower_stmt): Handle casts from large/huge BITINT_TYPEs to POINTER_TYPE/REFERENCE_TYPE as final_cast_p. * gcc.dg/bitint-82.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-02-01 10:36:08.408867602 +0100 +++ gcc/gimple-lower-bitint.cc 2024-02-01 11:47:21.233840956 +0100 @@ -5264,7 +5264,8 @@ bitint_large_huge::lower_stmt (gimple *s mergeable_cast_p = true; else if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large - && INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || POINTER_TYPE_P (TREE_TYPE (lhs)))) { final_cast_p = true; if (TREE_CODE (rhs1) == SSA_NAME @@ -5393,8 +5394,9 @@ bitint_large_huge::lower_stmt (gimple *s be needed. */ gcc_assert (TYPE_PRECISION (lhs_type) <= 2 * limb_prec); gimple *g; - if (TREE_CODE (lhs_type) == BITINT_TYPE - && bitint_precision_kind (lhs_type) == bitint_prec_middle) + if ((TREE_CODE (lhs_type) == BITINT_TYPE + && bitint_precision_kind (lhs_type) == bitint_prec_middle) + || POINTER_TYPE_P (lhs_type)) lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (lhs_type), TYPE_UNSIGNED (lhs_type)); m_data_cnt = 0; --- gcc/testsuite/gcc.dg/bitint-82.c.jj 2024-02-01 11:55:37.995866642 +0100 +++ gcc/testsuite/gcc.dg/bitint-82.c 2024-02-01 11:54:16.998003815 +0100 @@ -0,0 +1,18 @@ +/* PR tree-optimization/113692 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c23" } */ + +#if __BITINT_MAXWIDTH__ >= 135 +_BitInt(135) i; +#else +_BitInt(63) i; +#endif + +void * +foo (void) +{ + void *ret = 0; + if (i & 1) + ret = (void *) 1; + return ret; +}