* [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425]
@ 2024-03-23 7:55 Jakub Jelinek
2024-03-23 10:15 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-03-23 7:55 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
The task of the build_bitint_stmt_ssa_conflicts hook for
tree-ssa-coalesce.cc next to special casing the
multiplication/division/modulo is to ignore statements with
large/huge _BitInt lhs which isn't in names bitmap and on the
other side pretend all uses of the stmt are used in a later stmt
(single user of that SSA_NAME or perhaps single user of lhs of
the single user etc.) where the lowering will actually emit the
code.
Unfortunately the function wasn't handling COMPLEX_TYPE of the large/huge
BITINT_TYPE, while the FE doesn't really support such types, they are
used under the hood for __builtin_{add,sub,mul}_overflow{,_p}, they are
also present or absent from the names bitmap and should be treated the same.
Without this patch, the operands of .ADD_OVERFLOW were incorrectly pretended
to be used right in that call statement rather than on the cast stmt from
IMAGPART_EXPR of .ADD_OVERFLOW return value to some integral type.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2024-03-23 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/114425
* gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Handle
_Complex large/huge _BitInt types like the large/huge _BitInt types.
* gcc.dg/torture/bitint-67.c: New test.
--- gcc/gimple-lower-bitint.cc.jj 2024-03-22 09:21:28.350087044 +0100
+++ gcc/gimple-lower-bitint.cc 2024-03-22 14:54:41.767972684 +0100
@@ -5902,20 +5902,25 @@ build_bitint_stmt_ssa_conflicts (gimple
if (is_gimple_assign (stmt))
{
lhs = gimple_assign_lhs (stmt);
- if (TREE_CODE (lhs) == SSA_NAME
- && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
- && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large)
+ if (TREE_CODE (lhs) == SSA_NAME)
{
- if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
- return;
- switch (gimple_assign_rhs_code (stmt))
+ tree type = TREE_TYPE (lhs);
+ if (TREE_CODE (type) == COMPLEX_TYPE)
+ type = TREE_TYPE (type);
+ if (TREE_CODE (type) == BITINT_TYPE
+ && bitint_precision_kind (type) >= bitint_prec_large)
{
- case MULT_EXPR:
- case TRUNC_DIV_EXPR:
- case TRUNC_MOD_EXPR:
- muldiv_p = true;
- default:
- break;
+ if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
+ return;
+ switch (gimple_assign_rhs_code (stmt))
+ {
+ case MULT_EXPR:
+ case TRUNC_DIV_EXPR:
+ case TRUNC_MOD_EXPR:
+ muldiv_p = true;
+ default:
+ break;
+ }
}
}
}
@@ -5947,27 +5952,37 @@ build_bitint_stmt_ssa_conflicts (gimple
auto_vec<tree, 16> worklist;
FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
- if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE
- && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large)
- {
- if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
- use (live, var);
- else
- worklist.safe_push (var);
- }
+ {
+ tree type = TREE_TYPE (var);
+ if (TREE_CODE (type) == COMPLEX_TYPE)
+ type = TREE_TYPE (type);
+ if (TREE_CODE (type) == BITINT_TYPE
+ && bitint_precision_kind (type) >= bitint_prec_large)
+ {
+ if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
+ use (live, var);
+ else
+ worklist.safe_push (var);
+ }
+ }
while (worklist.length () > 0)
{
tree s = worklist.pop ();
FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_USE)
- if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE
- && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large)
- {
- if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
- use (live, var);
- else
- worklist.safe_push (var);
- }
+ {
+ tree type = TREE_TYPE (var);
+ if (TREE_CODE (type) == COMPLEX_TYPE)
+ type = TREE_TYPE (type);
+ if (TREE_CODE (type) == BITINT_TYPE
+ && bitint_precision_kind (type) >= bitint_prec_large)
+ {
+ if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
+ use (live, var);
+ else
+ worklist.safe_push (var);
+ }
+ }
}
if (muldiv_p)
--- gcc/testsuite/gcc.dg/torture/bitint-67.c.jj 2024-03-22 14:53:52.929642342 +0100
+++ gcc/testsuite/gcc.dg/torture/bitint-67.c 2024-03-22 14:54:29.205144953 +0100
@@ -0,0 +1,29 @@
+/* PR tree-optimization/114425 */
+/* { 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__ >= 2000
+_BitInt(8) a;
+_BitInt(300) b;
+_BitInt(2000) c;
+
+__attribute__((noipa)) unsigned
+foo (_BitInt(2000) d)
+{
+ int o = __builtin_add_overflow_p (d, 0, b);
+ _BitInt(2000) m = c * a;
+ unsigned u = m;
+ return u + o;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 2000
+ if (foo (0xfa7ac16f2613255eeb217e871c1f02221e26ce11f82d6a33206ec0ad5d4414722019933c0e2wb) != 1)
+ __builtin_abort ();
+#endif
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425]
2024-03-23 7:55 [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425] Jakub Jelinek
@ 2024-03-23 10:15 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-03-23 10:15 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Richard Biener, gcc-patches
> Am 23.03.2024 um 08:56 schrieb Jakub Jelinek <jakub@redhat.com>:
>
> Hi!
>
> The task of the build_bitint_stmt_ssa_conflicts hook for
> tree-ssa-coalesce.cc next to special casing the
> multiplication/division/modulo is to ignore statements with
> large/huge _BitInt lhs which isn't in names bitmap and on the
> other side pretend all uses of the stmt are used in a later stmt
> (single user of that SSA_NAME or perhaps single user of lhs of
> the single user etc.) where the lowering will actually emit the
> code.
>
> Unfortunately the function wasn't handling COMPLEX_TYPE of the large/huge
> BITINT_TYPE, while the FE doesn't really support such types, they are
> used under the hood for __builtin_{add,sub,mul}_overflow{,_p}, they are
> also present or absent from the names bitmap and should be treated the same.
>
> Without this patch, the operands of .ADD_OVERFLOW were incorrectly pretended
> to be used right in that call statement rather than on the cast stmt from
> IMAGPART_EXPR of .ADD_OVERFLOW return value to some integral type.
>
> 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/114425
> * gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Handle
> _Complex large/huge _BitInt types like the large/huge _BitInt types.
>
> * gcc.dg/torture/bitint-67.c: New test.
>
> --- gcc/gimple-lower-bitint.cc.jj 2024-03-22 09:21:28.350087044 +0100
> +++ gcc/gimple-lower-bitint.cc 2024-03-22 14:54:41.767972684 +0100
> @@ -5902,20 +5902,25 @@ build_bitint_stmt_ssa_conflicts (gimple
> if (is_gimple_assign (stmt))
> {
> lhs = gimple_assign_lhs (stmt);
> - if (TREE_CODE (lhs) == SSA_NAME
> - && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
> - && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large)
> + if (TREE_CODE (lhs) == SSA_NAME)
> {
> - if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
> - return;
> - switch (gimple_assign_rhs_code (stmt))
> + tree type = TREE_TYPE (lhs);
> + if (TREE_CODE (type) == COMPLEX_TYPE)
> + type = TREE_TYPE (type);
> + if (TREE_CODE (type) == BITINT_TYPE
> + && bitint_precision_kind (type) >= bitint_prec_large)
> {
> - case MULT_EXPR:
> - case TRUNC_DIV_EXPR:
> - case TRUNC_MOD_EXPR:
> - muldiv_p = true;
> - default:
> - break;
> + if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
> + return;
> + switch (gimple_assign_rhs_code (stmt))
> + {
> + case MULT_EXPR:
> + case TRUNC_DIV_EXPR:
> + case TRUNC_MOD_EXPR:
> + muldiv_p = true;
> + default:
> + break;
> + }
> }
> }
> }
> @@ -5947,27 +5952,37 @@ build_bitint_stmt_ssa_conflicts (gimple
>
> auto_vec<tree, 16> worklist;
> FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
> - if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE
> - && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large)
> - {
> - if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
> - use (live, var);
> - else
> - worklist.safe_push (var);
> - }
> + {
> + tree type = TREE_TYPE (var);
> + if (TREE_CODE (type) == COMPLEX_TYPE)
> + type = TREE_TYPE (type);
> + if (TREE_CODE (type) == BITINT_TYPE
> + && bitint_precision_kind (type) >= bitint_prec_large)
> + {
> + if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
> + use (live, var);
> + else
> + worklist.safe_push (var);
> + }
> + }
>
> while (worklist.length () > 0)
> {
> tree s = worklist.pop ();
> FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_USE)
> - if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE
> - && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large)
> - {
> - if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
> - use (live, var);
> - else
> - worklist.safe_push (var);
> - }
> + {
> + tree type = TREE_TYPE (var);
> + if (TREE_CODE (type) == COMPLEX_TYPE)
> + type = TREE_TYPE (type);
> + if (TREE_CODE (type) == BITINT_TYPE
> + && bitint_precision_kind (type) >= bitint_prec_large)
> + {
> + if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
> + use (live, var);
> + else
> + worklist.safe_push (var);
> + }
> + }
> }
>
> if (muldiv_p)
> --- gcc/testsuite/gcc.dg/torture/bitint-67.c.jj 2024-03-22 14:53:52.929642342 +0100
> +++ gcc/testsuite/gcc.dg/torture/bitint-67.c 2024-03-22 14:54:29.205144953 +0100
> @@ -0,0 +1,29 @@
> +/* PR tree-optimization/114425 */
> +/* { 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__ >= 2000
> +_BitInt(8) a;
> +_BitInt(300) b;
> +_BitInt(2000) c;
> +
> +__attribute__((noipa)) unsigned
> +foo (_BitInt(2000) d)
> +{
> + int o = __builtin_add_overflow_p (d, 0, b);
> + _BitInt(2000) m = c * a;
> + unsigned u = m;
> + return u + o;
> +}
> +#endif
> +
> +int
> +main ()
> +{
> +#if __BITINT_MAXWIDTH__ >= 2000
> + if (foo (0xfa7ac16f2613255eeb217e871c1f02221e26ce11f82d6a33206ec0ad5d4414722019933c0e2wb) != 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:55 [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425] Jakub Jelinek
2024-03-23 10:15 ` 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).