aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/gimple-lower-bitint.cc11
-rw-r--r--gcc/testsuite/gcc.dg/torture/bitint-60.c24
-rw-r--r--gcc/testsuite/gcc.dg/torture/bitint-61.c36
3 files changed, 67 insertions, 4 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index fb03063..3552fdd 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -4255,12 +4255,12 @@ bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt)
NULL_TREE, NULL_TREE);
gimple *g2 = NULL;
if (!single_comparison)
- g2 = gimple_build_cond (LT_EXPR, idx,
+ g2 = gimple_build_cond (EQ_EXPR, idx,
size_int (prec_limbs - 1),
NULL_TREE, NULL_TREE);
edge edge_true_true, edge_true_false, edge_false;
if_then_if_then_else (g, g2, profile_probability::likely (),
- profile_probability::likely (),
+ profile_probability::unlikely (),
edge_true_true, edge_true_false,
edge_false);
tree l = limb_access (type, var ? var : obj, idx, true);
@@ -4269,8 +4269,11 @@ bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt)
if (!single_comparison)
{
m_gsi = gsi_after_labels (edge_true_true->src);
- l = limb_access (type, var ? var : obj,
- size_int (prec_limbs - 1), true);
+ tree plm1idx = size_int (prec_limbs - 1);
+ tree plm1type = limb_access_type (type, plm1idx);
+ l = limb_access (type, var ? var : obj, plm1idx, true);
+ if (!useless_type_conversion_p (plm1type, TREE_TYPE (rhs)))
+ rhs = add_cast (plm1type, rhs);
if (!useless_type_conversion_p (TREE_TYPE (l),
TREE_TYPE (rhs)))
rhs = add_cast (TREE_TYPE (l), rhs);
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-60.c b/gcc/testsuite/gcc.dg/torture/bitint-60.c
new file mode 100644
index 0000000..d2d27a1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-60.c
@@ -0,0 +1,24 @@
+/* PR tree-optimization/114040 */
+/* { 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" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 8671
+__attribute__((noipa)) unsigned
+foo (unsigned _BitInt(8671) x, unsigned y, unsigned _BitInt(512) z)
+{
+ unsigned _BitInt (8671) r
+ = x * __builtin_sub_overflow_p (y * z, 0, (unsigned _BitInt(255)) 0);
+ return r;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 8671
+ if (foo (1, 1, 0xfffa46471e7c2dd60000000000000000wb))
+ __builtin_abort ();
+#endif
+}
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-61.c b/gcc/testsuite/gcc.dg/torture/bitint-61.c
new file mode 100644
index 0000000..e5651f10
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-61.c
@@ -0,0 +1,36 @@
+/* PR tree-optimization/114040 */
+/* { dg-do run { target { bitint && int128 } } } */
+/* { dg-options "-std=c23" } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+unsigned a;
+signed char b;
+short c;
+long d;
+__int128 e;
+int f;
+
+#if __BITINT_MAXWIDTH__ >= 511
+__attribute__((noinline)) void
+foo (_BitInt(3) x, unsigned _BitInt(511) y, unsigned *z)
+{
+ int g = __builtin_sub_overflow_p (y ^ x, 0, (unsigned _BitInt(255)) 0);
+ unsigned h = y + e, i = h + d;
+ unsigned _BitInt(2) j = i + g;
+ unsigned k = j + c;
+ unsigned l = k + a + f + b;
+ *z = l;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 511
+ unsigned x;
+ foo (0, 0x81e4a5fa7c408f370000000000000000uwb, &x);
+ if (x)
+ __builtin_abort ();
+#endif
+}