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.