* [PATCH] bitint: Fix bitfield loads in handle_cast [PR114433]
@ 2024-03-23 7:59 Jakub Jelinek
2024-03-23 10:16 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-03-23 7:59 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
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 <jakub@redhat.com>
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.
--- 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
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] bitint: Fix bitfield loads in handle_cast [PR114433]
2024-03-23 7:59 [PATCH] bitint: Fix bitfield loads in handle_cast [PR114433] Jakub Jelinek
@ 2024-03-23 10:16 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-03-23 10:16 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Richard Biener, gcc-patches
> Am 23.03.2024 um 08:59 schrieb Jakub Jelinek <jakub@redhat.com>:
>
> 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?
Ok
Richard
> 2024-03-23 Jakub Jelinek <jakub@redhat.com>
>
> 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.
>
> --- 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
> +}
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-23 10:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-23 7:59 [PATCH] bitint: Fix bitfield loads in handle_cast [PR114433] Jakub Jelinek
2024-03-23 10:16 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).