aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-03-23 11:19:09 +0100
committerJakub Jelinek <jakub@redhat.com>2024-03-23 11:19:09 +0100
commitf92cf8cbbe199bda70d0dd7893e8c8836777e2d0 (patch)
treed725407a317f5462aae1e5d0b8a770a3b32afadd
parent8fc5593df8e0d36cc5bd8ea21097a491a634a866 (diff)
downloadgcc-f92cf8cbbe199bda70d0dd7893e8c8836777e2d0.zip
gcc-f92cf8cbbe199bda70d0dd7893e8c8836777e2d0.tar.gz
gcc-f92cf8cbbe199bda70d0dd7893e8c8836777e2d0.tar.bz2
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.
-rw-r--r--gcc/gimple-lower-bitint.cc71
-rw-r--r--gcc/testsuite/gcc.dg/torture/bitint-67.c29
2 files changed, 72 insertions, 28 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 8c26800..6f13c65 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 0000000..b5621e1
--- /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
+}