From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id E327D3858D34; Thu, 4 Apr 2024 08:47:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E327D3858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712220451; bh=VLOAxPwWZpSxgywoyX+CNzksZt/vMfe1shVXS/zT2B0=; h=From:To:Subject:Date:From; b=ZkH08UtiP7+rFBg4c1OFu2FDmdtKzWOb4V4cEWAxNUbk+0+OaiAWDpLS4XydLT5FY B7/SnIeldoLYLPdnfF1ylfJmRPIsqWdUkM0sjfsAUxXn7uYA5at7yzOk6Urgktaf6k F83eWws/IG+duc/avN/y4rf3moJOLC9nMZhQLRck= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9783] bitint: Handle m_bitfld_load cast in outer m_cast_conditional [PR114555] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: f2ccfb2d0b2698e6b140e4d09e53b701a3193384 X-Git-Newrev: 48530efdcccb154d3ed200246384edc162debc5d Message-Id: <20240404084731.E327D3858D34@sourceware.org> Date: Thu, 4 Apr 2024 08:47:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:48530efdcccb154d3ed200246384edc162debc5d commit r14-9783-g48530efdcccb154d3ed200246384edc162debc5d Author: Jakub Jelinek Date: Thu Apr 4 10:47:00 2024 +0200 bitint: Handle m_bitfld_load cast in outer m_cast_conditional [PR114555] 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). 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. Diff: --- gcc/gimple-lower-bitint.cc | 20 +++++++++++++++++++- gcc/testsuite/gcc.dg/bitint-103.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/bitint-104.c | 17 +++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index 40a1084afb3..1afd4de445a 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -1506,7 +1506,7 @@ bitint_large_huge::handle_cast (tree lhs_type, tree rhs1, tree idx) 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_type, tree rhs1, tree idx) 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; diff --git a/gcc/testsuite/gcc.dg/bitint-103.c b/gcc/testsuite/gcc.dg/bitint-103.c new file mode 100644 index 00000000000..4d8104959a1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-103.c @@ -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 +} diff --git a/gcc/testsuite/gcc.dg/bitint-104.c b/gcc/testsuite/gcc.dg/bitint-104.c new file mode 100644 index 00000000000..b4aac83137b --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-104.c @@ -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 +}