From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] lower-bitint: Fix up lowering of huge _BitInt 0 PHI args [PR113120]
Date: Thu, 4 Jan 2024 10:00:18 +0100 [thread overview]
Message-ID: <ZZZzov90j4WZ/03I@tucnak> (raw)
Hi!
The PHI argument expansion of INTEGER_CSTs where bitint_min_cst_precision
returns significantly smaller precision than the PHI result precision is
optimized by loading the much smaller constant (if any) from memory and
then either setting the remaining limbs to {} or calling memset with -1.
The case where no constant is loaded (i.e. c == NULL) is when the
INTEGER_CST is 0 or all_ones - in that case we can just set all the limbs
to {} or call memset with -1 on everything.
While for the all ones extension case that is what the code was already
doing, I missed one spot in the zero extension case, where constricting
the offset of the MEM_REF lhs of the = {} store it was using unconditionally
the byte size of c, which obviously doesn't work if c is NULL. In that case
we want to use zero offset.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2024-01-04 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/113120
* gimple-lower-bitint.cc (gimple_lower_bitint): Fix handling of very
large _BitInt zero INTEGER_CST PHI argument.
* gcc.dg/bitint-62.c: New test.
--- gcc/gimple-lower-bitint.cc.jj 2024-01-03 11:51:27.000000000 +0100
+++ gcc/gimple-lower-bitint.cc 2024-01-03 13:53:30.699328045 +0100
@@ -6582,8 +6582,12 @@ gimple_lower_bitint (void)
= build_array_type_nelts (large_huge.m_limb_type,
nelts);
tree ptype = build_pointer_type (TREE_TYPE (v1));
- tree off = fold_convert (ptype,
- TYPE_SIZE_UNIT (TREE_TYPE (c)));
+ tree off;
+ if (c)
+ off = fold_convert (ptype,
+ TYPE_SIZE_UNIT (TREE_TYPE (c)));
+ else
+ off = build_zero_cst (ptype);
tree vd = build2 (MEM_REF, vtype,
build_fold_addr_expr (v1), off);
g = gimple_build_assign (vd, build_zero_cst (vtype));
--- gcc/testsuite/gcc.dg/bitint-62.c.jj 2024-01-03 14:11:22.332301884 +0100
+++ gcc/testsuite/gcc.dg/bitint-62.c 2024-01-03 14:10:58.219640178 +0100
@@ -0,0 +1,32 @@
+/* PR tree-optimization/113120 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+_BitInt(8) a;
+_BitInt(55) b;
+
+#if __BITINT_MAXWIDTH__ >= 401
+static __attribute__((noinline, noclone)) void
+foo (unsigned _BitInt(1) c, _BitInt(401) d)
+{
+ c /= d << b;
+ a = c;
+}
+
+void
+bar (void)
+{
+ foo (1, 4);
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 6928
+_BitInt(6928)
+baz (int x, _BitInt(6928) y)
+{
+ if (x)
+ return y;
+ else
+ return 0;
+}
+#endif
Jakub
next reply other threads:[~2024-01-04 9:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 9:00 Jakub Jelinek [this message]
2024-01-08 12:48 ` 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=ZZZzov90j4WZ/03I@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).