aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-11-19 10:25:04 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2024-11-19 10:25:04 +0100
commit758d2b3d3e28c831c79f5c18727d149c81896434 (patch)
tree9801cbde12e24207552adcdd020725d0a6bac1b7 /gcc
parentc5b33fab3e932afd5eaf253bc0f1e547ca2a058f (diff)
downloadgcc-758d2b3d3e28c831c79f5c18727d149c81896434.zip
gcc-758d2b3d3e28c831c79f5c18727d149c81896434.tar.gz
gcc-758d2b3d3e28c831c79f5c18727d149c81896434.tar.bz2
bitintlower: Handle EXACT_DIV_EXPR like TRUNC_DIV_EXPR in bitint lowering [PR117571]
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-lower-bitint.cc8
-rw-r--r--gcc/testsuite/gcc.dg/bitint-114.c23
2 files changed, 31 insertions, 0 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 1d1e300..6fc4253 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -3597,6 +3597,7 @@ bitint_large_huge::lower_muldiv_stmt (tree obj, gimple *stmt)
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,
@@ -5560,6 +5561,7 @@ bitint_large_huge::lower_stmt (gimple *stmt)
return;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
lower_muldiv_stmt (lhs, g);
goto handled;
@@ -5694,6 +5696,7 @@ bitint_large_huge::lower_stmt (gimple *stmt)
return;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
lower_muldiv_stmt (NULL_TREE, stmt);
return;
@@ -5740,6 +5743,7 @@ stmt_needs_operand_addr (gimple *stmt)
{
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
case FLOAT_EXPR:
return true;
@@ -5931,6 +5935,7 @@ build_bitint_stmt_ssa_conflicts (gimple *stmt, live_track *live,
{
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
muldiv_p = true;
default:
@@ -6174,6 +6179,7 @@ gimple_lower_bitint (void)
break;
case MULT_EXPR:
case TRUNC_DIV_EXPR:
+ case EXACT_DIV_EXPR:
case TRUNC_MOD_EXPR:
if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s))
{
@@ -6455,6 +6461,7 @@ gimple_lower_bitint (void)
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
@@ -6568,6 +6575,7 @@ gimple_lower_bitint (void)
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:
diff --git a/gcc/testsuite/gcc.dg/bitint-114.c b/gcc/testsuite/gcc.dg/bitint-114.c
new file mode 100644
index 0000000..27db4ac
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-114.c
@@ -0,0 +1,23 @@
+/* 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