From patchwork Sat Mar 23 07:59:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1915107 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=JOPRslwj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4V1s6h0Pcmz1yXr for ; Sat, 23 Mar 2024 18:59:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3F5A3858D1E for ; Sat, 23 Mar 2024 07:59:37 +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 CBA9A3858D28 for ; Sat, 23 Mar 2024 07:59:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBA9A3858D28 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 CBA9A3858D28 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=1711180763; cv=none; b=uYbT4f8ZdTEzKiBOTqnK3zgmiVU6ySKNJFgcCalDEwqWQmSsEdl3jliBaR2N4RbT0PDtMXWCW9d9TPdsNshBBY+P4n3Eax5VWfDWOrO3J0x1jvKZmc2RZKZfoQQvZxXzbLYbE/bwHZDnti52hBAf4XjoGwL5vifDe2swJARPT+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711180763; c=relaxed/simple; bh=dcaNA/RoVkJ2jw1ELA/wDaGaLUCOWkFEMlnCcSF6Al0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Bn0Nlw9Hjutrcd3gZ1zZ8jx8dAFnR8/g1aq9njESzROcMGApYNbG1mR763m4kIj7vc8qH1jhw0N5yViA8iGdQJN2xdbULwl0VZRxUhpqC6Ia0ueo4Ub/4gVHMAcffiWh1zw6Sx+aj2gc/yhl5PM3jJ78p++rwL9s59VCZl2vKkg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711180761; 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=WVcgIs96EHp0AEZO+AKciL090cbu9UzcqdRsFRd8jFI=; b=JOPRslwjTltQBTE0x7QmtBDJc2oLW8frRooY4tVrF89OntQHA6kymRxoISwZa6buyyHU5X 7BuJpsmb2z4fz2rpPX9dUivy+tJNhx7VGoMWdjam0kA86JJt8koS2VVQqgrNQaKgoe/eNK t+b3KsUmGWFg6m4r0AxNnxqsxjrFXtQ= 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-583-jRE5RS-WO8O2BxoB54sJvQ-1; Sat, 23 Mar 2024 03:59:19 -0400 X-MC-Unique: jRE5RS-WO8O2BxoB54sJvQ-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 58391101A523; Sat, 23 Mar 2024 07:59:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BCDC492BD0; Sat, 23 Mar 2024 07:59:18 +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 42N7x75I270071 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 23 Mar 2024 08:59:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42N7x6Tp270070; Sat, 23 Mar 2024 08:59:06 +0100 Date: Sat, 23 Mar 2024 08:59:06 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Fix bitfield loads in handle_cast [PR114433] 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=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! We ICE on the following testcase, because handle_cast was incorrectly testing !m_first to see whether it should use m_data[m_bitfld_load + 1] or fresh SSA_NAME for a PHI result. Now, m_first is in the routine sometimes temporarily cleared in between doing prepare_data_in_out and the !m_first check and only before returning restored from the save_first copy. Without this patch, we try to use the same SSA_NAME (_12 here) in 2 different PHI results which is obviously invalid IL and ICEs very quickly. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-23 Jakub Jelinek PR tree-optimization/114433 * gimple-lower-bitint.cc (bitint_large_huge::handle_cast): For m_bitfld_load check save_first rather than m_first. * gcc.dg/torture/bitint-68.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-03-22 14:54:41.767972684 +0100 +++ gcc/gimple-lower-bitint.cc 2024-03-22 17:13:43.702249666 +0100 @@ -1506,7 +1506,7 @@ bitint_large_huge::handle_cast (tree lhs if (m_bitfld_load) { tree t4; - if (!m_first) + if (!save_first) t4 = m_data[m_bitfld_load + 1]; else t4 = make_ssa_name (m_limb_type); --- gcc/testsuite/gcc.dg/torture/bitint-68.c.jj 2024-03-22 17:26:29.841713520 +0100 +++ gcc/testsuite/gcc.dg/torture/bitint-68.c 2024-03-22 17:26:51.941409603 +0100 @@ -0,0 +1,28 @@ +/* PR tree-optimization/114433 */ +/* { 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__ >= 511 +struct S { int : 31; _BitInt(511) b : 300; } s; + +__attribute__((noipa)) _BitInt(511) +foo (void) +{ + return s.b << 1; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 511 + s.b = 642460398785925402356009598661384732715767737595497615767135001949421105426024498988100867wb; + if (foo () != ((_BitInt(511)) 642460398785925402356009598661384732715767737595497615767135001949421105426024498988100867wb) << 1) + __builtin_abort (); + s.b = 2655156766298562299560755420298083843774074962786295887660222690220887wb; + if (foo () != ((_BitInt(511)) 2655156766298562299560755420298083843774074962786295887660222690220887wb) << 1) + __builtin_abort (); +#endif +}