[cfe-dev] [RFC] Introduce overflow builtins

Xi Wang xi.wang at gmail.com
Tue Mar 27 20:13:11 PDT 2012


On Mar 23, 2012, at 3:57 PM, Dave Zarzycki wrote:

> On Mar 22, 2012, at 10:48 PM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:
> 
>> On Thu, Mar 22, 2012 at 05:41:18PM -0700, Eli Friedman wrote:
>>> Assuming the point of these builtins is primarily performance of
>>> library implementations (since most projects would need some sort of
>>> fallback for compilers which don't provide this builtin), I'm not sure
>>> it makes sense to have div/rem at all; there isn't any underlying
>>> llvm.div.with.overflow to map it to...
>> 
>> Signed division can overflow (INT_MIN / -1). There is also the question
>> of division by 0. It seems natural to consider it as overflow in which
>> case both div and rem make sense.
> 
> 
> Given that people are going to use these builtins to implement secure/safe code, 
> it would also be nice if __builtin_overflow_div() also _forced_ people to think about both the quotient and remainder at the same time. For example: __builtin_overflow_div(T *quotient, T *remainder, T value, T divisor).


As Eli said, there's no such thing as llvm.div.with.overflow ---
I am not sure if there's any performance gain from compiler support.

I would rather to leave div/rem/shl/shr for overflow libraries.
It's straightforward to define a function or macro to perform
overflow checking for them.

- xi





More information about the cfe-dev mailing list