aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-01-08 13:58:28 +0100
committerJakub Jelinek <jakub@redhat.com>2024-01-08 13:58:28 +0100
commitefef8d7ff43c6c489fd6e7c52d71494d21324c87 (patch)
treed25d5883fdc1e4c6247ed02e770f781cbc7c70e6
parent7590d975ecfdae4f112b5086c017101c08f07e3e (diff)
downloadgcc-efef8d7ff43c6c489fd6e7c52d71494d21324c87.zip
gcc-efef8d7ff43c6c489fd6e7c52d71494d21324c87.tar.gz
gcc-efef8d7ff43c6c489fd6e7c52d71494d21324c87.tar.bz2
lower-bitint: Fix up lowering of huge _BitInt 0 PHI args [PR113120]
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. 2024-01-08 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.
-rw-r--r--gcc/gimple-lower-bitint.cc8
-rw-r--r--gcc/testsuite/gcc.dg/bitint-62.c32
2 files changed, 38 insertions, 2 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 3869a16..8993a61 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -6606,8 +6606,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));
diff --git a/gcc/testsuite/gcc.dg/bitint-62.c b/gcc/testsuite/gcc.dg/bitint-62.c
new file mode 100644
index 0000000..2c3139c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-62.c
@@ -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