public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9640] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425]
@ 2024-03-23 10:19 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-03-23 10:19 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f92cf8cbbe199bda70d0dd7893e8c8836777e2d0
commit r14-9640-gf92cf8cbbe199bda70d0dd7893e8c8836777e2d0
Author: Jakub Jelinek <jakub@redhat.com>
Date: Sat Mar 23 11:19:09 2024 +0100
bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425]
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.
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.
Diff:
---
gcc/gimple-lower-bitint.cc | 71 +++++++++++++++++++-------------
gcc/testsuite/gcc.dg/torture/bitint-67.c | 29 +++++++++++++
2 files changed, 72 insertions(+), 28 deletions(-)
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 8c268005dfd..6f13c657c6b 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -5902,20 +5902,25 @@ build_bitint_stmt_ssa_conflicts (gimple *stmt, live_track *live,
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 *stmt, live_track *live,
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)
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-67.c b/gcc/testsuite/gcc.dg/torture/bitint-67.c
new file mode 100644
index 00000000000..b5621e1b21b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-67.c
@@ -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
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-03-23 10:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-23 10:19 [gcc r14-9640] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425] Jakub Jelinek
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).