[PATCH] Convert manual unsigned +/- overflow checking into {ADD,SUB}_OVERFLOW (PR target/67089)
Richard Biener
rguenther@suse.de
Wed Nov 25 09:12:00 GMT 2015
On Wed, 25 Nov 2015, Jakub Jelinek wrote:
> On Wed, Nov 25, 2015 at 09:58:15AM +0100, Marc Glisse wrote:
> > I guess it got lost in my text, but if a user writes:
> >
> > unsigned diff = a - b;
> > if (b > a) { /* overflow */ ... }
> > else { ... }
> >
> > Your patch will not detect it. It seems that replacing x-y>x with y>x could
>
> Sorry, already committed the patch (without incremental that hasn't been
> tested anyway).
> It is true that the patch does not detect this, but it is harder that way.
> What if it is
> if (b > a) ...
> // Huge amount of code
> r = a - b;
> ? Trying to emit the subtraction above the comparison would then very
> likely increase register preassure. So, I'd really prefer doing x-y>x to y>x
> only for single use.
I think that's ok for now. For the above case you'd need to do sth
similar to what cse sincos / divmod do, with an added "cost" check
(same basic-block?).
Richard.
More information about the Gcc-patches
mailing list