From patchwork Wed Mar 13 08:33:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1911557 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=hjqg7y9u; 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 4TvkNJ6GGwz1yWn for ; Wed, 13 Mar 2024 19:35:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D32623858029 for ; Wed, 13 Mar 2024 08:35:09 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id E706C3858C36 for ; Wed, 13 Mar 2024 08:33:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E706C3858C36 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 E706C3858C36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710318851; cv=none; b=KnQqx9u/ZKMtWWCdgprZajxG9/YppbViJFWH7EIQb1/xA18C6f7IbQSqxDMiu7KK9/O1xdmBqycXCMryo3UA8jmVgQ1GXsu206HA7hzqpaJUSGZi0NMblQ5rLGk/pz0sRO9ef1xQ7ilLKz6s2wCmTspzjvTBa89PkAAlC5nw3Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710318851; c=relaxed/simple; bh=XpsVq0Y5iAPid3PyFvnzTKNsbmOk77TLpS6+gvdFS4U=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=aUBWITOLgxsfL4553IKUK1vwdmRQuT4cg1NBZH/UM/DNp7JcPTbQojxYNCI8ykQTFdo8gbQw7176lDzXJ14KrrKlesLfdCn5ZD1rdRb0sAINnv3rDYGYbbTTf86z5a4hsz/f+rNxRksXM4kXdU7qLPeHrwvyfjtC3a0BuiH715g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710318838; 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=fP+ZwVrzp40zLKBvXSY6H6BQgAywxF9kyFg7jKcsF6w=; b=hjqg7y9utrYShI0OQHIIRzDYByHWG9YynUmQfnIRvaJT0xto5IOs92uHAlb81gmF7jFuV9 Zj4wSsxO/m63KcgXPwX3M3LYCNq3MTyCZJN+kgiCAqydHrF/8efFnZnG+AMOJ4hsqFq14x IktsrOfX9K6JITofNZiQJwpXgqeavN0= 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-260-UfK2tPbwM3SFR05D9UmL1A-1; Wed, 13 Mar 2024 04:33:55 -0400 X-MC-Unique: UfK2tPbwM3SFR05D9UmL1A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 9770E84B061; Wed, 13 Mar 2024 08:33:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.225.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CDDC492BC7; Wed, 13 Mar 2024 08:33:55 +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 42D8XrGa689897 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 13 Mar 2024 09:33:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42D8XrcC689896; Wed, 13 Mar 2024 09:33:53 +0100 Date: Wed, 13 Mar 2024 09:33:53 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Fix up lowering of bitfield loads/stores [PR114313] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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, 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! The following testcase ICEs, because for large/huge _BitInt bitfield loads/stores we use the DECL_BIT_FIELD_REPRESENTATIVE as the underlying "var" and indexes into it can be larger than the precision of the bitfield might normally allow. The following patch fixes that by passing NULL_TREE type in that case to limb_access, so that we always return m_limb_type type and don't do the extra assertions, after all, the callers expect that too. I had to add the first hunk to avoid ICE, it was using type in one place even when it was NULL. But TYPE_SIZE (TREE_TYPE (var)) seems like the right size to use anyway because the code uses VIEW_CONVERT_EXPR on it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-13 Jakub Jelinek PR middle-end/114313 * gimple-lower-bitint.cc (bitint_large_huge::limb_access): Use TYPE_SIZE of TREE_TYPE (var) rather than TYPE_SIZE of type. (bitint_large_huge::handle_load): Pass NULL_TREE rather than rhs_type to limb_access for the bitfield load cases. (bitint_large_huge::lower_mergeable_stmt): Pass NULL_TREE rather than lhs_type to limb_access if nlhs is non-NULL. * gcc.dg/torture/bitint-62.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-03-05 10:27:04.609415622 +0100 +++ gcc/gimple-lower-bitint.cc 2024-03-12 16:45:50.152914901 +0100 @@ -640,7 +640,7 @@ bitint_large_huge::limb_access (tree typ TREE_TYPE (TREE_TYPE (var)))) { unsigned HOST_WIDE_INT nelts - = CEIL (tree_to_uhwi (TYPE_SIZE (type)), limb_prec); + = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var))), limb_prec); tree atype = build_array_type_nelts (ltype, nelts); var = build1 (VIEW_CONVERT_EXPR, atype, var); } @@ -1854,7 +1854,7 @@ bitint_large_huge::handle_load (gimple * m_gsi = gsi_after_labels (gsi_bb (m_gsi)); else gsi_next (&m_gsi); - tree t = limb_access (rhs_type, nrhs1, size_int (bo_idx), true); + tree t = limb_access (NULL_TREE, nrhs1, size_int (bo_idx), true); tree iv = make_ssa_name (m_limb_type); g = gimple_build_assign (iv, t); insert_before (g); @@ -1941,7 +1941,7 @@ bitint_large_huge::handle_load (gimple * tree iv2 = NULL_TREE; if (nidx0) { - tree t = limb_access (rhs_type, nrhs1, nidx0, true); + tree t = limb_access (NULL_TREE, nrhs1, nidx0, true); iv = make_ssa_name (m_limb_type); g = gimple_build_assign (iv, t); insert_before (g); @@ -1966,7 +1966,7 @@ bitint_large_huge::handle_load (gimple * if_then (g, profile_probability::likely (), edge_true, edge_false); } - tree t = limb_access (rhs_type, nrhs1, nidx1, true); + tree t = limb_access (NULL_TREE, nrhs1, nidx1, true); if (m_upwards_2limb && !m_first && !m_bitfld_load @@ -2728,8 +2728,8 @@ bitint_large_huge::lower_mergeable_stmt /* Otherwise, stores to any other lhs. */ if (!done) { - tree l = limb_access (lhs_type, nlhs ? nlhs : lhs, - nidx, true); + tree l = limb_access (nlhs ? NULL_TREE : lhs_type, + nlhs ? nlhs : lhs, nidx, true); g = gimple_build_assign (l, rhs1); } insert_before (g); @@ -2873,7 +2873,8 @@ bitint_large_huge::lower_mergeable_stmt /* Otherwise, stores to any other lhs. */ if (!done) { - tree l = limb_access (lhs_type, nlhs ? nlhs : lhs, nidx, true); + tree l = limb_access (nlhs ? NULL_TREE : lhs_type, + nlhs ? nlhs : lhs, nidx, true); g = gimple_build_assign (l, rhs1); } insert_before (g); --- gcc/testsuite/gcc.dg/torture/bitint-62.c.jj 2024-03-12 16:40:38.400198787 +0100 +++ gcc/testsuite/gcc.dg/torture/bitint-62.c 2024-03-12 16:41:43.988297525 +0100 @@ -0,0 +1,28 @@ +/* PR middle-end/114313 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c23" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 256 +struct S { _BitInt(257) : 257; _BitInt(256) b : 182; } s; + +__attribute__((noipa)) _BitInt(256) +foo (void) +{ + return s.b; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 256 + s.b = 1414262180967678524960294186228886540125217087586381431wb; + if (foo () != 1414262180967678524960294186228886540125217087586381431wb) + __builtin_abort (); + s.b = -581849792837428541666755934071828568425158644418477999wb; + if (foo () != -581849792837428541666755934071828568425158644418477999wb) + __builtin_abort (); +#endif +}