From patchwork Thu Apr 4 07:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 88014 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6EECC3858C50 for ; Thu, 4 Apr 2024 07:30:34 +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 E5AEA3858D34 for ; Thu, 4 Apr 2024 07:30:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5AEA3858D34 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 E5AEA3858D34 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=1712215807; cv=none; b=C+w1IxxP6DRRc+sCHlFHOeiKpaQyRPtxnehQlpulVjX/dIMEw7HSaKqLm6lGzLyoGPCjNW1Ltculh+vE1l4P2wpTx/XU0EbixOA3Y2NNOnc2OlHe1Z8asB/ucr5Z+j7wnpdjSSgvISt7UqhmonBgyvtQCy9UWYmTqp0eoS7tMXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712215807; c=relaxed/simple; bh=Bbv8YAPcOK2isedeliJB9y3DxERTb7Gg6mrk0EZ1YYU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=t+3fzgGhid7d/BxryV5w67EcFTnGunEtZLQNjDKEXqGEQgcfggFO34kkP4B9hFQt1Q829x/q6kbqWus09rBg1uE6LVX+qFzRcNrGorESJgOol3eiM7RblXzxugULncnpBR4iSNjduFy0yyOh433+lYsmJrw6kUbN+vT6ZGX9YRw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712215803; 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=Wy2bJ0Or8ujDjX9b1EVjtuF70WaldT0qh1xo2k7K6aY=; b=hv35Pvp6O/y/xQvSN7NJ3PVThM+tnQFTh/zwX5CQDhmJE1H74GYqKQ9GhcaqKW3o47IF0O xP4sLmZDBroHKyE7rIbP32ueqJE4OQLouNTTLz7IYkh/lkxZwGJAHglHWhxqrXM2aIfqGY n4M0ArR27BeeH7FogY7N6dVzBKk4Xyw= 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-310-tc90o3IQPwa9z7BVyBtlNA-1; Thu, 04 Apr 2024 03:30:01 -0400 X-MC-Unique: tc90o3IQPwa9z7BVyBtlNA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 3F2F1101A520; Thu, 4 Apr 2024 07:30:01 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 054A440C6CB3; Thu, 4 Apr 2024 07:30:00 +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 4347TdMo780923 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 4 Apr 2024 09:29:39 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4347Tdmj780922; Thu, 4 Apr 2024 09:29:39 +0200 Date: Thu, 4 Apr 2024 09:29:38 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Handle m_bitfld_load cast in outer m_cast_conditional [PR114555] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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, 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+patchwork=sourceware.org@gcc.gnu.org Hi! We ICE on the following testcase, because we use result of a PHI node which is only conditional because of a m_cast_conditional on the outermost loops PHI node argument and so is invalid SSA form. The following patch fixes it like similar cases elsewhere by adding needed intervening PHI(s). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-04-04 Jakub Jelinek PR tree-optimization/114555 * gimple-lower-bitint.cc (bitint_large_huge::handle_cast): For m_bitfld_load and save_cast_conditional add any needed PHIs and adjust t4 accordingly. * gcc.dg/bitint-103.c: New test. * gcc.dg/bitint-104.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-03-23 11:19:53.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2024-04-03 15:31:19.686583203 +0200 @@ -1506,7 +1506,7 @@ bitint_large_huge::handle_cast (tree lhs if (m_bitfld_load) { tree t4; - if (!save_first) + if (!save_first && !save_cast_conditional) t4 = m_data[m_bitfld_load + 1]; else t4 = make_ssa_name (m_limb_type); @@ -1519,6 +1519,24 @@ bitint_large_huge::handle_cast (tree lhs if (edge_true_true) add_phi_arg (phi, m_data[m_bitfld_load], edge_true_true, UNKNOWN_LOCATION); + if (save_cast_conditional) + for (basic_block bb = gsi_bb (m_gsi);;) + { + edge e1 = single_succ_edge (bb); + edge e2 = find_edge (e1->dest, m_bb), e3; + tree t5 = ((e2 && !save_first) ? m_data[m_bitfld_load + 1] + : make_ssa_name (m_limb_type)); + phi = create_phi_node (t5, e1->dest); + edge_iterator ei; + FOR_EACH_EDGE (e3, ei, e1->dest->preds) + add_phi_arg (phi, (e3 == e1 ? t4 + : build_zero_cst (m_limb_type)), + e3, UNKNOWN_LOCATION); + t4 = t5; + if (e2) + break; + bb = e1->dest; + } m_data[m_bitfld_load] = t4; m_data[m_bitfld_load + 2] = t4; m_bitfld_load = 0; --- gcc/testsuite/gcc.dg/bitint-103.c.jj 2024-04-03 15:34:19.468113199 +0200 +++ gcc/testsuite/gcc.dg/bitint-103.c 2024-04-03 15:34:05.805300917 +0200 @@ -0,0 +1,16 @@ +/* PR tree-optimization/114555 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +#if __BITINT_MAXWIDTH__ >= 1225 +struct S { _BitInt(512) : 98; _BitInt(1225) b : 509; } s; +_BitInt(1225) a; +#endif + +void +foo (void) +{ +#if __BITINT_MAXWIDTH__ >= 1225 + a ^= (unsigned _BitInt(1025)) s.b; +#endif +} --- gcc/testsuite/gcc.dg/bitint-104.c.jj 2024-04-03 15:36:59.385916107 +0200 +++ gcc/testsuite/gcc.dg/bitint-104.c 2024-04-03 15:36:28.034346850 +0200 @@ -0,0 +1,17 @@ +/* PR tree-optimization/114555 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O -fno-tree-forwprop" } */ + +#if __BITINT_MAXWIDTH__ >= 4139 +struct S { _BitInt(31) : 6; _BitInt(513) b : 241; } s; +_BitInt(4139) a; +#endif + +void +foo (void) +{ +#if __BITINT_MAXWIDTH__ >= 4139 + int i = 0; + a -= s.b << i; +#endif +}