[PATCH] Added llvm.is.constant intrinsic

Sobczak, Janusz janusz.sobczak at mobica.com
Wed Jul 2 02:51:54 PDT 2014


On 1 July 2014 14:13, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:
> On Tue, Jul 01, 2014 at 01:59:13PM +0200, Sobczak, Janusz wrote:
>> What uses of _builtin_constant_p() are sensible and what uses are, in
>> fact, abuses is an interesting topic for a discussion. Nevertheless,
>> current status is that one can use __builtin_constant_p() in inline
>> functions and it will work as expected when compiled with gcc but
>> __builtin_constant_p() would always return false if compiled with clang.
>
> Because they are not constant, yes. Code not compiling with -O0 was a

gcc disagrees :)

> problem for a long time on Linux for exactly this reason.
>
>> This macro swaps the bytes at compile time if it is possible or calls arch
>> specific, fast swab implementations if 'x' is not known to be constant
>> (i.e. calls __builtin_swab() if compiler supports it).
>
> We are doing similar things in NetBSD. The question remains why it is
> not the other way around -- call __builtin_swab if it is available and
> "manual" logic otherwise. That one will get proper compile-time
> evaluation if possible. This is exactly the kind of situation I
> was talking about initially.

The other way around, the code would look like this:
if (have __builtin_swab)
    __builtin_swab(x)
else if (__builtin_constant_p(x))
    __compile_time_swab(x)
else
    __runtime_arch_specific_swab(x)

We're drifting off-topic.


-- 
Janusz Sobczak
Mobica Ltd
www.mobica.com <http://www.mobica.com>


*Mobica is a provider of software engineering, testing and consultancy
services based in the UK, Poland and the USA, with a worldwide customer
base. We have a proven track record in delivering innovative solutions to
some of the world’s best-known companies in a range of sectors including
Automotive, Mobile, Semiconductor, Finance, TV, Marine and Aviation.*




More information about the llvm-commits mailing list