[Bug tree-optimization/96697] Failure to optimize mod+div to 0

amacleod at redhat dot com gcc-bugzilla@gcc.gnu.org
Mon Jul 12 19:56:11 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96697

--- Comment #5 from Andrew Macleod <amacleod at redhat dot com> ---
(In reply to Andrew Macleod from comment #4)
> (In reply to Jakub Jelinek from comment #2)
> > Shall we do that as a specific matcher or e.g. in the ranger once it gets
> > code for symbolic comparisons?  I mean, for signed t = x % y note that t is
> > in [-y + 1, y + 1] and on the division use that information to determine the
> > division result range to be [0, 0] ?
> > It could then handle even e.g. ((unsigned) x % y) / (y + 32) for signed y
> > etc.
> 
> IN theory the ranger should handle this when relations are available.
> 
>     <bb 2> :
>     _1 = x_2(D) % y_3(D);       // Establish relation _1 < y_3
>     _4 = _1 / y_3(D);
>     return _4;
> 
> IT should recognize the relation _1 < y_3 from the first statement and when
> we calculate _1 / y_3, it again ought to then apply the relation and
> determine that _4 = [0,0]

hum.  but that'd only work for unsigned I guess?  If y_3 is negative, then _1 >
y_3 I believe.   so if y_3 is VARYING, relations won't solve this issue :-P


More information about the Gcc-bugs mailing list