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: 1894448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KUUhzL33; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TRB111dZzz1yhq for ; Fri, 2 Feb 2024 20:53:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EDAA3858D33 for ; Fri, 2 Feb 2024 09:53:22 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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; +}