This is the mail archive of the
mailing list for the GCC project.
Re: New no-undefined-overflow branch
On Fri, Mar 6, 2009 at 3:29 PM, Paolo Bonzini <firstname.lastname@example.org> wrote:
>> So while trapping variants can certainly be introduced it looks like
>> this task may be more difficult.
> I don't think you need to introduce trapping tree codes. ?You can
> introduce them directly in the front-end as
> ? s = x +nv y
I think this should be
s = x + y
otherwise the compiler can assume that for the following check
the addition did not overflow.
> ? (((s ^ x) & (s ^ y)) < 0) ? trap () : s
> ? d = x -nv y
> ? (((d ^ x) & (x ^ y)) < 0) ? trap () : d
> ? (b == INT_MIN ? trap () : -nv b)
> ? (int)((long long) a * (long long) b) == a *nv b ? trap () : a *nv b
> Making sure they are compiled efficiently is another story, but
> especially for the sake of LTO I think this is the way to go.
I agree. Btw, for the addition case we generate
leal (%rsi,%rdi), %eax
xorl %eax, %esi
xorl %eax, %edi
testl %edi, %esi
which isn't too bad.