This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/58742] pointer arithmetic simplification
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 29 Jan 2014 12:25:02 +0000
- Subject: [Bug middle-end/58742] pointer arithmetic simplification
- Auto-submitted: auto-generated
- References: <bug-58742-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58742
--- Comment #21 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ok, I have a patch that does the remaining (including the duplicate bug). But
for the (p + sz) - p case it can only optimize the sizeof (*p) == 1 without
range information - for example for
__SIZE_TYPE__
fx (int *a, __SIZE_TYPE__ sz)
{
int *b = a + sz;
return b - a;
}
we get
fx (int * a, long unsigned int sz)
{
int * b;
long unsigned int _2;
long int _7;
long int _8;
long unsigned int _9;
<bb 2>:
_2 = sz_1(D) * 4;
_7 = (long int) _2;
_8 = _7 /[ex] 4;
_9 = (long unsigned int) _8;
return _9;
}
as result which is basically (sz * 4) /[ex] 4 as we don't know whether
the multiplication by 4 overflows (well, the C language may say it
doesn't but the IL does not reflect this). If we make 'sz' a signed
int then VRP could later optimize this (but it doesn't currently),
or forwprop could use range information. On RTL we manage to optimize
the signed int input case.