[cfe-dev] [RFC] Introduce overflow builtins

Eli Friedman eli.friedman at gmail.com
Wed Mar 28 19:17:12 PDT 2012


On Wed, Mar 28, 2012 at 7:02 PM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> On Wed, Mar 28, 2012 at 02:56:23PM -0400, Xi Wang wrote:
>> On Mar 28, 2012, at 9:26 AM, Joerg Sonnenberger wrote:
>>
>> > On Tue, Mar 27, 2012 at 11:13:11PM -0400, Xi Wang wrote:
>> >> As Eli said, there's no such thing as llvm.div.with.overflow ---
>> >
>> > Just because it hasn't been done...
>> >
>> >> I am not sure if there's any performance gain from compiler support.
>> >
>> > At least for x86, the same argument applies here as for the other cases:
>> > you can detect it with a trivial flag compare. An additional branch, if
>> > you also want to handle divisor of 0.
>>
>> Which case did you mean?  The same argument holds for signed division,
>> but probably not for unsigned division and shifts.
>>
>> If the LLVM IR adds llvm.sdiv.with.overflow, we can definitely add
>> a corresponding builtin.  I feel like it is better to leave the
>> rest cases to an overflow library, and have the compiler focus on
>> providing minimum necessary support for overflow detection (rather
>> than implementing a complete library itself).
>
> As originally said, a large point of doing it in the compiler is making
> sure it is low overhead. unsigned divisions can't overflow in the
> traditional sense. There is still the point of divide by zero and
> depending on where you come from, it is a form of overflow. I don't
> believe merging division and remainder computation forcefully provides
> any value -- modulo can't overflow

INT_MIN % -1 in C is undefined.

-Eli




More information about the cfe-dev mailing list