* [PATCH] lower-bitint: Fix up VIEW_CONVERT_EXPR handling in lower_mergeable_stmt [PR113568]
@ 2024-01-27 8:05 Jakub Jelinek
2024-01-27 12:03 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-01-27 8:05 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
We generally allow merging mergeable stmts with some final cast (but not
further casts or mergeable operations after the cast). As some casts
are handled conditionally, if (idx < cst) handle_operand (idx); else if
idx == cst) handle_operand (cst); else ..., we must sure that e.g. the
mergeable PLUS_EXPR/MINUS_EXPR/NEGATE_EXPR never appear in handle_operand
called from such casts, because it ICEs on invalid SSA_NAME form (that part
could be fixable by adding further PHIs) but also because we'd need to
correctly propagate the overflow flags from the if to else if.
So, instead lower_mergeable_stmt handles an outermost widening cast (or
widening cast feeding outermost store) specially.
The problem was similar to PR113408, that VIEW_CONVERT_EXPR tree is
present in the gimple_assign_rhs1 while it is not for NOP_EXPR/CONVERT_EXPR,
so the checks whether the outermost cast should be handled didn't handle
the VCE case and so handle_plus_minus was called from the conditional
handle_cast.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2024-01-27 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/113568
* gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt):
For VIEW_CONVERT_EXPR use first operand of rhs1 instead of rhs1
in the widening extension checks.
* gcc.dg/bitint-78.c: New test.
--- gcc/gimple-lower-bitint.cc.jj 2024-01-26 17:40:29.083814064 +0100
+++ gcc/gimple-lower-bitint.cc 2024-01-26 18:05:24.461891138 +0100
@@ -2401,6 +2401,8 @@ bitint_large_huge::lower_mergeable_stmt
rhs1 = gimple_assign_rhs1 (store_operand
? SSA_NAME_DEF_STMT (store_operand)
: stmt);
+ if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
+ rhs1 = TREE_OPERAND (rhs1, 0);
/* Optimize mergeable ops ending with widening cast to _BitInt
(or followed by store). We can lower just the limbs of the
cast operand and widen afterwards. */
--- gcc/testsuite/gcc.dg/bitint-78.c.jj 2024-01-26 18:11:54.164435951 +0100
+++ gcc/testsuite/gcc.dg/bitint-78.c 2024-01-26 18:11:33.642723218 +0100
@@ -0,0 +1,21 @@
+/* PR tree-optimization/113568 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2 -std=c23" } */
+
+signed char c;
+#if __BITINT_MAXWIDTH__ >= 464
+_BitInt(464) g;
+
+void
+foo (void)
+{
+ _BitInt(464) a[2] = {};
+ _BitInt(464) b;
+ while (c)
+ {
+ b = g + 1;
+ g = a[0];
+ a[0] = b;
+ }
+}
+#endif
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] lower-bitint: Fix up VIEW_CONVERT_EXPR handling in lower_mergeable_stmt [PR113568]
2024-01-27 8:05 [PATCH] lower-bitint: Fix up VIEW_CONVERT_EXPR handling in lower_mergeable_stmt [PR113568] Jakub Jelinek
@ 2024-01-27 12:03 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-01-27 12:03 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
> Am 27.01.2024 um 09:16 schrieb Jakub Jelinek <jakub@redhat.com>:
>
> Hi!
>
> We generally allow merging mergeable stmts with some final cast (but not
> further casts or mergeable operations after the cast). As some casts
> are handled conditionally, if (idx < cst) handle_operand (idx); else if
> idx == cst) handle_operand (cst); else ..., we must sure that e.g. the
> mergeable PLUS_EXPR/MINUS_EXPR/NEGATE_EXPR never appear in handle_operand
> called from such casts, because it ICEs on invalid SSA_NAME form (that part
> could be fixable by adding further PHIs) but also because we'd need to
> correctly propagate the overflow flags from the if to else if.
> So, instead lower_mergeable_stmt handles an outermost widening cast (or
> widening cast feeding outermost store) specially.
> The problem was similar to PR113408, that VIEW_CONVERT_EXPR tree is
> present in the gimple_assign_rhs1 while it is not for NOP_EXPR/CONVERT_EXPR,
> so the checks whether the outermost cast should be handled didn't handle
> the VCE case and so handle_plus_minus was called from the conditional
> handle_cast.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
Ok
Richard
> 2024-01-27 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/113568
> * gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt):
> For VIEW_CONVERT_EXPR use first operand of rhs1 instead of rhs1
> in the widening extension checks.
>
> * gcc.dg/bitint-78.c: New test.
>
> --- gcc/gimple-lower-bitint.cc.jj 2024-01-26 17:40:29.083814064 +0100
> +++ gcc/gimple-lower-bitint.cc 2024-01-26 18:05:24.461891138 +0100
> @@ -2401,6 +2401,8 @@ bitint_large_huge::lower_mergeable_stmt
> rhs1 = gimple_assign_rhs1 (store_operand
> ? SSA_NAME_DEF_STMT (store_operand)
> : stmt);
> + if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
> + rhs1 = TREE_OPERAND (rhs1, 0);
> /* Optimize mergeable ops ending with widening cast to _BitInt
> (or followed by store). We can lower just the limbs of the
> cast operand and widen afterwards. */
> --- gcc/testsuite/gcc.dg/bitint-78.c.jj 2024-01-26 18:11:54.164435951 +0100
> +++ gcc/testsuite/gcc.dg/bitint-78.c 2024-01-26 18:11:33.642723218 +0100
> @@ -0,0 +1,21 @@
> +/* PR tree-optimization/113568 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-O2 -std=c23" } */
> +
> +signed char c;
> +#if __BITINT_MAXWIDTH__ >= 464
> +_BitInt(464) g;
> +
> +void
> +foo (void)
> +{
> + _BitInt(464) a[2] = {};
> + _BitInt(464) b;
> + while (c)
> + {
> + b = g + 1;
> + g = a[0];
> + a[0] = b;
> + }
> +}
> +#endif
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-27 12:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-27 8:05 [PATCH] lower-bitint: Fix up VIEW_CONVERT_EXPR handling in lower_mergeable_stmt [PR113568] Jakub Jelinek
2024-01-27 12:03 ` 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).