[cfe-dev] [RFC] Introduce overflow builtins

Chris Lattner clattner at apple.com
Sat Mar 24 19:04:20 PDT 2012


On Mar 22, 2012, at 6:12 AM, Xi Wang wrote:

> On Mar 22, 2012, at 12:20 AM, Chris Lattner wrote:
> 
>> Regardless of whether we expose builtins, it would be nice for the optimizer to recognize common idioms, this is just general goodness for a wide range of already-written code.
> 
> I agree.
> 
>>> Let's consider adding overflow builtins to Clang, in the form:
>>> 
>>> 	bool __overflow_*(T*, T, T);
>>> 
>>> With overflow builtins, programmers can implement the example
>>> as follows.
>> 
>> This sort of prototype makes sense to me, given that C doesn't support multiple return values well.  The builtin should start with __builtin though.  This is a pretty obvious set of functionality, is there any established practice in other compilers (e.g. MSVC, ICC, or even other more obscure ones?).  If there is standing practice somewhere else, it would be best to follow that lead, must so that we don't have to eventually implement both.
> 
> Just out of curiosity, why __builtin_*?  We already have __sync_* and __atomic_*. ;-)

AFAIK, these came to GCC through a spec established by the Itanium ABI, not because they fit well :)

>  Actually I used __builtin_saddo (__builtin_sadd_with_overflow is just too long).  Since this "saddo" looked a little bizarre to me, I changed it to __overflow_sadd.

I don't think a long name is a bad thing.  These builtins will be rarely used, it's just that they are important when they do get used.

> I was also wondering which would be better, __overflow_*(T*, T, T) or __overflow_*(T, T, T*).

I don't have a preference one way or the other.  Are there any precedents?

> I didn't find overflow intrinsics in msvc and icc.

Ok.

-Chris




More information about the cfe-dev mailing list