From patchwork Wed Mar 20 09:29:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1914016 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=VXGR0osu; 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 4V03Gg3FXzz1yWy for ; Wed, 20 Mar 2024 20:30:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2348385842A for ; Wed, 20 Mar 2024 09:30:16 +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 E49903858D1E for ; Wed, 20 Mar 2024 09:29:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E49903858D1E 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 E49903858D1E 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=1710926995; cv=none; b=XCI7ECgv6/WQkU3zlcSSi1V0n7j/Ez3fr2NkxW1DQPpllbKlsDDqBCca+V5ycRdcZ9Vv54gyTrkgvxiexbP/+uSN5E+goc5/mFJS6KcfSSpAl8E7L5oTF5EXLPqEgAQ9a/mTm/lwfWXBMHaCka2sdPrLlJcu/AGjfHuy7LqZyTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710926995; c=relaxed/simple; bh=ciwp2plF1GrzkN0rYdmo2MrS7quPYhoCrYqU8wwHGwo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=FX7EWn3Jy3v9Rj3Si3GaZaBpHQenJN2BfMdUksIuixCfaSK+tGvspsmXq9+94EPStv9AFYos0gtJM04tdVnFcVStXv9R6W/L5mUBk2TisPuqE3tc76o4YtI5y5PhF2b+5Mkt3pMXIOccWkie570CNInXkaflIj4xqD7gP1tESMU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710926993; 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=Kb8KTeteSeJJg6YtwMR1H41VYWpuFBCPMDNLAOtggPo=; b=VXGR0osuynYqjEvh9pVDjZbHaoJB9H2rw7CHhzizpcLRPqB6aH8WPEZiCbpN/+RZM46H04 S6ILaBpV/snVCayukt4teLtAazlC+S6R98As/bI27ip9XhEwviaF62VUoSZ9G7yqNvmqKF ga6wH5IjGYPHgXuva07XrmVKIF1uxOw= 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-658-A5LWOZouOp29_MEfIukCiA-1; Wed, 20 Mar 2024 05:29:50 -0400 X-MC-Unique: A5LWOZouOp29_MEfIukCiA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 B34C685A58B; Wed, 20 Mar 2024 09:29:49 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77E14111E406; Wed, 20 Mar 2024 09:29:49 +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 42K9Tgvx4108807 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 20 Mar 2024 10:29:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42K9TgA14108806; Wed, 20 Mar 2024 10:29:42 +0100 Date: Wed, 20 Mar 2024 10:29:41 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Fix handling of conditional bitfield loads [PR114365] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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! For the m_var_msb (aka left shift) case of large/huge _BitInt bitfield loads handle_load adds a PHI node, but I forgot to actually update the temporary the code later on uses, so the PHI result was unused and the code incorrectly used something that wasn't valid SSA form. In particular, we emitted if (_29 != 2) goto ; [80.00%] else goto ; [20.00%] [local count: 1073741824]: _33 = VIEW_CONVERT_EXPR(s.D.2771)[_31]; [local count: 1073741824]: # _34 = PHI <_33(4), 0(3)> _35 = _32 >> 31; _36 = _33 << 33; _37 = _36 | _35; _38 = _37 << _19; where instead of _33 the _36 def stmt should be using _34. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-20 Jakub Jelinek PR tree-optimization/114365 * gimple-lower-bitint.cc (bitint_large_huge::handle_load): When adding a PHI node, set iv2 to its result afterwards. * gcc.dg/bitint-102.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-03-16 15:15:22.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2024-03-19 10:45:31.006649671 +0100 @@ -2026,6 +2026,7 @@ bitint_large_huge::handle_load (gimple * add_phi_arg (phi, build_zero_cst (m_limb_type), edge_false, UNKNOWN_LOCATION); m_gsi = gsi_after_labels (edge_true->dest); + iv2 = iv3; } } g = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR, --- gcc/testsuite/gcc.dg/bitint-102.c.jj 2024-03-19 10:54:15.317327543 +0100 +++ gcc/testsuite/gcc.dg/bitint-102.c 2024-03-19 10:53:57.162580193 +0100 @@ -0,0 +1,18 @@ +/* PR tree-optimization/114365 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +struct S { + int : 31; +#if __BITINT_MAXWIDTH__ >= 129 + _BitInt(129) b : 129; +#else + _BitInt(63) b : 63; +#endif +} s; + +void +foo (int a) +{ + s.b <<= a; +}