This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/33259] limited range of remainder operation can prove loop runs at most once
- From: "raeburn at raeburn dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Aug 2008 18:18:37 -0000
- Subject: [Bug tree-optimization/33259] limited range of remainder operation can prove loop runs at most once
- References: <bug-33259-11337@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from raeburn at raeburn dot org 2008-08-16 18:18 -------
Just noting for future reference: I looked at the VRP results and that does
seem to be where the optimization opportunity is missed; x%y with constant y is
VARYING if x is, though it seems to me the result should be
[-abs(y)+1,abs(y)-1] for signed math and [0,abs(y)-1] for unsigned math. If x
can be constrained to either nonnegative or nonpositive, that reduces the range
in the signed case, and if it has a shorter range [x1,x2] where
floor(x1/y)==floor(x2/y) it might be constrained further still. If y has a
range, the result is still bound by the larger of the absolute values of the
ends of the range.
(Similarly, though not related to this case, x/const can't be larger than
type_max(x)/const. Seems to me that in general there are a few cases where
varying should be treated as [type_min,type_max] and processed like any other
range, but maybe I'm missing something.)
I experimented with a patch to tree-vrp.c to support
TRUNC_MOD_EXPR(varying,const), and found I also had to get VRP to understand
BIT_NOT_EXPR, but then it generated the same code for both test functions. The
patch needs work still, and I need to understand the infinity and overflow
stuff in tree-vrp.c a little better to make sure I'm not breaking something.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33259