imm_use_iterator ui;
use_operand_p use_p;
int seen = 0;
+ gimple *realpart = NULL, *cast = NULL;
FOR_EACH_IMM_USE_FAST (use_p, ui, lhs)
{
gimple *g = USE_STMT (use_p);
if ((seen & 1) != 0)
return 0;
seen |= 1;
+ realpart = g;
}
else if (gimple_assign_rhs_code (g) == IMAGPART_EXPR)
{
if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs2))
|| TREE_CODE (TREE_TYPE (lhs2)) == BITINT_TYPE)
return 0;
+ cast = use_stmt;
}
else
return 0;
}
if ((seen & 2) == 0)
return 0;
- return seen == 3 ? 2 : 1;
+ if (seen == 3)
+ {
+ /* Punt if the cast stmt appears before realpart stmt, because
+ if both appear, the lowering wants to emit all the code
+ at the location of realpart stmt. */
+ gimple_stmt_iterator gsi = gsi_for_stmt (realpart);
+ unsigned int cnt = 0;
+ do
+ {
+ gsi_prev_nondebug (&gsi);
+ if (gsi_end_p (gsi) || gsi_stmt (gsi) == cast)
+ return 0;
+ if (gsi_stmt (gsi) == stmt)
+ return 2;
+ /* If realpart is too far from stmt, punt as well.
+ Usually it will appear right after it. */
+ if (++cnt == 32)
+ return 0;
+ }
+ while (1);
+ }
+ return 1;
}
/* If STMT is some kind of comparison (GIMPLE_COND, comparison assignment)
--- /dev/null
+/* PR tree-optimization/113119 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+_BitInt(8) b;
+_Bool c;
+#if __BITINT_MAXWIDTH__ >= 8445
+_BitInt(8445) a;
+
+void
+foo (_BitInt(4058) d)
+{
+ c = __builtin_add_overflow (a, 0ULL, &d);
+ __builtin_add_overflow (a, 0ULL, &d);
+ b = d;
+}
+#endif