[Bug tree-optimization/127092] [17 Regression] Ranger folds CEIL_DIV_EXPR and ROUND_DIV_EXPR to zero for some nonnegative operands that satisfy a < b
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Sep 2 16:30:32 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127092
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrea Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:0acb69bf9bb0db14b7e230fb5370257c530fb6e8
commit r17-3869-g0acb69bf9bb0db14b7e230fb5370257c530fb6e8
Author: Andrea Pinski <andrew.pinski@oss.qualcomm.com>
Date: Mon Aug 31 21:22:49 2026 -0700
range-op: Fix some divisions [PR127092]
This was an oversight of not knowing there are a few different
integer divisions and how they will round.
When `a < b` and for non-negative a and b, `a/b` will be 0 iff for
truncate (TRUNC_DIV_EXPR), exact (EXACT_DIV_EXPR)
and floor division (FLOOR_DIV_EXPR).
Ceiling division (CEIL_DIV_EXPR) will be 1 for positive a and zero when a
is 0.
Rounding division (ROUND_DIV_EXPR) it is based on the how far a is from b.
We can skip the ceiling division case since it is not used that much.
And rounding division case is too hard to figure out here so that is
skipped
also.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/127092
gcc/ChangeLog:
* range-op.cc (operator_div::op1_op2_relation_effect): Only
handle TRUNC_DIV_EXPR, EXACT_DIV_EXPR and FLOOR_DIV_EXPR
for the `a < b` case.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr127092-1.f90: New test.
Signed-off-by: Andrea Pinski <andrew.pinski@oss.qualcomm.com>
More information about the Gcc-bugs
mailing list