def (live, lhs, graph);
}
+/* If STMT is .{ADD,SUB,MUL}_OVERFLOW with INTEGER_CST arguments,
+ return the largest bitint_prec_kind of them, otherwise return
+ bitint_prec_small. */
+
+static bitint_prec_kind
+arith_overflow_arg_kind (gimple *stmt)
+{
+ bitint_prec_kind ret = bitint_prec_small;
+ if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
+ switch (gimple_call_internal_fn (stmt))
+ {
+ case IFN_ADD_OVERFLOW:
+ case IFN_SUB_OVERFLOW:
+ case IFN_MUL_OVERFLOW:
+ for (int i = 0; i < 2; ++i)
+ {
+ tree a = gimple_call_arg (stmt, i);
+ if (TREE_CODE (a) == INTEGER_CST
+ && TREE_CODE (TREE_TYPE (a)) == BITINT_TYPE)
+ {
+ bitint_prec_kind kind = bitint_precision_kind (TREE_TYPE (a));
+ ret = MAX (ret, kind);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return ret;
+}
+
/* Entry point for _BitInt(N) operation lowering during optimization. */
static unsigned int
continue;
tree type = TREE_TYPE (s);
if (TREE_CODE (type) == COMPLEX_TYPE)
- type = TREE_TYPE (type);
+ {
+ if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s))
+ != bitint_prec_small)
+ break;
+ type = TREE_TYPE (type);
+ }
if (TREE_CODE (type) == BITINT_TYPE
&& bitint_precision_kind (type) != bitint_prec_small)
break;
continue;
tree type = TREE_TYPE (s);
if (TREE_CODE (type) == COMPLEX_TYPE)
- type = TREE_TYPE (type);
+ {
+ if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s))
+ >= bitint_prec_large)
+ has_large_huge = true;
+ type = TREE_TYPE (type);
+ }
if (TREE_CODE (type) == BITINT_TYPE
&& bitint_precision_kind (type) >= bitint_prec_large)
{
{
bitint_prec_kind this_kind
= bitint_precision_kind (TREE_TYPE (t));
- if (this_kind > kind)
- kind = this_kind;
+ kind = MAX (kind, this_kind);
}
if (is_gimple_assign (stmt) && gimple_store_p (stmt))
{
{
bitint_prec_kind this_kind
= bitint_precision_kind (TREE_TYPE (t));
- if (this_kind > kind)
- kind = this_kind;
+ kind = MAX (kind, this_kind);
}
}
if (is_gimple_assign (stmt)
{
bitint_prec_kind this_kind
= bitint_precision_kind (TREE_TYPE (t));
- if (this_kind > kind)
- kind = this_kind;
+ kind = MAX (kind, this_kind);
}
}
if (is_gimple_call (stmt))
{
t = gimple_call_lhs (stmt);
- if (t
- && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
- && TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == BITINT_TYPE)
+ if (t && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE)
{
- bitint_prec_kind this_kind
- = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t)));
- if (this_kind > kind)
- kind = this_kind;
+ bitint_prec_kind this_kind = arith_overflow_arg_kind (stmt);
+ kind = MAX (kind, this_kind);
+ if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == BITINT_TYPE)
+ {
+ this_kind
+ = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t)));
+ kind = MAX (kind, this_kind);
+ }
}
}
if (kind == bitint_prec_small)
--- /dev/null
+/* PR tree-optimization/113003 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+#if __BITINT_MAXWIDTH__ >= 131
+int
+foo (_BitInt(7) x)
+{
+ return __builtin_mul_overflow_p (x, 1046555807606105294475452482332716433408wb, 0);
+}
+
+#ifdef __SIZEOF_INT128__
+int
+bar (unsigned __int128 x)
+{
+ return __builtin_sub_overflow_p (340282366920938463463374607431768211457uwb, x, 0);
+}
+#endif
+#else
+int i;
+#endif