r15-4601 added match.pd simplification of some TRUNC_DIV_EXPR expressions
into EXACT_DIV_EXPR, so bitintlower can now encounter even those.
From bitint lowering POV the fact that the division will be exact
doesn't matter, we still need to call at runtime the __divmodbitint4
API and it wouldn't simplify there anything to know it is exact if
we duplicated that, so the following patch lowers EXACT_DIV_EXPR exactly
as TRUNC_DIV_EXPR.
I think we don't need to backport this unless something introduces
EXACT_DIV_EXPR on BITINT_TYPEd expressions on the 14 branch as well.
2024-11-19 Jakub Jelinek <jakub@redhat.com>
PR middle-end/117571
* gimple-lower-bitint.cc (bitint_large_huge::lower_muldiv_stmt,
bitint_large_huge::lower_stmt, stmt_needs_operand_addr,
build_bitint_stmt_ssa_conflicts, gimple_lower_bitint): Handle
EXACT_DIV_EXPR like TRUNC_DIV_EXPR.
* gcc.dg/bitint-114.c: New test.
insert_before (g);
break;
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
g = gimple_build_call_internal (IFN_DIVMODBITINT, 8,
lhs, build_int_cst (sitype, prec),
null_pointer_node,
return;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
lower_muldiv_stmt (lhs, g);
goto handled;
return;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
lower_muldiv_stmt (NULL_TREE, stmt);
return;
{
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
case FLOAT_EXPR:
return true;
{
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
muldiv_p = true;
default:
break;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s))
{
switch (gimple_assign_rhs_code (use_stmt))
{
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
case FLOAT_EXPR:
/* For division, modulo and casts to floating
case RSHIFT_EXPR:
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
case FIX_TRUNC_EXPR:
case REALPART_EXPR:
--- /dev/null
+/* PR middle-end/117571 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2" } */
+
+#if __BITINT_MAXWIDTH__ >= 255
+_BitInt(255) b;
+
+_BitInt(255)
+foo ()
+{
+ return (b << 10) / 2;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 8192
+_BitInt(8192) c;
+
+_BitInt(8192)
+bar ()
+{
+ return (c << 1039) / 0x20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000wb;
+}
+#endif