From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425]
Date: Sat, 23 Mar 2024 08:55:18 +0100 [thread overview]
Message-ID: <Zf6K5mSRbfFdPe5q@tucnak> (raw)
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
next reply other threads:[~2024-03-23 7:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-23 7:55 Jakub Jelinek [this message]
2024-03-23 10:15 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zf6K5mSRbfFdPe5q@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).