aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/gimple-lower-bitint.cc11
-rw-r--r--gcc/testsuite/gcc.dg/torture/bitint-83.c48
2 files changed, 59 insertions, 0 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 1224173..e7c7fe5 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -3181,6 +3181,17 @@ bitint_large_huge::lower_mergeable_stmt (gimple *stmt, tree_code &cmp_code,
{
tree l = limb_access (nlhs ? NULL_TREE : lhs_type,
nlhs ? nlhs : lhs, idx, true);
+
+ if (bitint_extended
+ && sext
+ && TYPE_UNSIGNED (lhs_type)
+ && tree_fits_uhwi_p (idx)
+ && !nlhs)
+ {
+ rhs1 = add_cast (limb_access_type (lhs_type, idx), rhs1);
+ rhs1 = add_cast (TREE_TYPE (l), rhs1);
+ }
+
g = gimple_build_assign (l, rhs1);
}
insert_before (g);
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-83.c b/gcc/testsuite/gcc.dg/torture/bitint-83.c
new file mode 100644
index 0000000..8a9df44
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-83.c
@@ -0,0 +1,48 @@
+/* Derived from a test in gcc.dg/torture/bitint-16.c */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#include "../bitintext.h"
+
+#define BASIC_TESTS \
+ TEST(8) \
+ TEST(16) \
+ TEST(32)
+
+#if __BITINT_MAXWIDTH__ >= 519
+#define ALL_TESTS \
+ BASIC_TESTS \
+ TEST(64) \
+ TEST(128) \
+ TEST(256) \
+ TEST(512)
+#else
+#define ALL_TESTS BASIC_TESTS
+#endif
+
+#define TEST(N) \
+void \
+test##N (unsigned _BitInt(N + 7) *t, _BitInt(N) x) \
+{ \
+ *t = -x; \
+}
+ALL_TESTS
+#undef TEST
+
+volatile int y = 0;
+
+int
+main (void)
+{
+#define TEST(N) \
+ { \
+ unsigned _BitInt(N + 7) t; \
+ _BitInt(N) x = y + N; \
+ test##N (&t, x); \
+ BEXTC (t); \
+ }
+ ALL_TESTS
+#undef TEST
+}